| 6 | 1/1 | 返回列表 |
| 查看: 697 | 回復(fù): 5 | ||
[求助]
各位大神們 ,幫幫我看看這個(gè)matlab中的類的構(gòu)造器,不勝感激! 已有1人參與
|
|
%af.m這是af類的構(gòu)造器。此處定義了人工魚類的數(shù)據(jù)結(jié)構(gòu) function af=af() af.x=0.5+rand(); af.y=rand(); %af.x=-5.12+10.24*rand(); %af.y=-5.12+10.24*rand(); af.try_number=100; af=class(af,'af'); matlab2011b運(yùn)行后總是提示: Error using class The CLASS function must be called from a class constructor. Error in af (line 8) af=class(af,'af'); 請(qǐng)問(wèn)各位大神,這樣的問(wèn)題該怎么解決?非常感謝 |

木蟲 (著名寫手)


木蟲 (著名寫手)

|
大神,我按上面的方法做了,但是又出現(xiàn)了其他錯(cuò)誤,你能幫我看看么? afsa Access to an object's fields is only permitted within its methods. Error in get (line 5) out=af.x; Error in afsa (line 29) afs_x(i)=get(afs{i},'x'); 其中,afsa是主函數(shù),get函數(shù)如下: %get.m此函數(shù)負(fù)責(zé)獲取人工魚的位置x,y的位置 function out=get(af,argin) switch argin case 'x' out=af.x; case 'y' out=af.y; case 'try_number' out=af.try_number; otherwise fprintf('參數(shù)錯(cuò)誤!\n'); end 這樣的錯(cuò)誤怎么解決。糠浅8屑! |

木蟲 (著名寫手)
|
嘿嘿給你說(shuō)有什么好處啊,唉 我是好人就給你說(shuō)了吧,你那個(gè)get函數(shù)也存成m文件,放到剛才的@的文件夾里面,才能直接用,也就是那個(gè)af和get函數(shù)都放在@af里面,然后就能調(diào)用。 再者,最好不要用get函數(shù)吧 get是獲取句柄對(duì)應(yīng)值用的,會(huì)有沖突,要不你換成getpos也行,不過(guò)你文件名要和對(duì)應(yīng)的函數(shù)名一致 |

| 6 | 1/1 | 返回列表 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 321求調(diào)劑 +8 | 何潤(rùn)采123 2026-03-18 | 8/400 |
|
|---|---|---|---|---|
|
[考研] 本人考085602 化學(xué)工程 專碩 +17 | 不知道叫什么! 2026-03-15 | 19/950 |
|
|
[考研] 一志愿天津大學(xué)化學(xué)工藝專業(yè)(081702)315分求調(diào)劑 +11 | yangfz 2026-03-17 | 11/550 |
|
|
[考研] 304求調(diào)劑 +3 | 曼殊2266 2026-03-18 | 3/150 |
|
|
[考研] 求調(diào)劑,一志愿:南京航空航天大學(xué)大學(xué) ,080500材料科學(xué)與工程學(xué)碩,總分289分 +3 | @taotao 2026-03-19 | 3/150 |
|
|
[考研] 328求調(diào)劑,英語(yǔ)六級(jí)551,有科研經(jīng)歷 +4 | 生物工程調(diào)劑 2026-03-16 | 12/600 |
|
|
[考研] 085410人工智能專碩317求調(diào)劑(0854都可以) +3 | xbxudjdn 2026-03-18 | 3/150 |
|
|
[考研] 311求調(diào)劑 +4 | 冬十三 2026-03-18 | 4/200 |
|
|
[考研] 295求調(diào)劑 +3 | 一志愿京區(qū)211 2026-03-18 | 5/250 |
|
|
[考研] 化學(xué)工程321分求調(diào)劑 +15 | 大米飯! 2026-03-15 | 18/900 |
|
|
[考研] 材料與化工一志愿南昌大學(xué)327求調(diào)劑推薦 +8 | Ncdx123456 2026-03-13 | 9/450 |
|
|
[考研] 280求調(diào)劑 +6 | 咕嚕曉曉 2026-03-18 | 7/350 |
|
|
[考博] 26博士申請(qǐng) +3 | 1042136743 2026-03-17 | 3/150 |
|
|
[考研] 材料與化工專碩調(diào)劑 +5 | heming3743 2026-03-16 | 5/250 |
|
|
[考研] 274求調(diào)劑 +5 | 時(shí)間點(diǎn) 2026-03-13 | 5/250 |
|
|
[考研] 288求調(diào)劑 +4 | 奇點(diǎn)0314 2026-03-14 | 4/200 |
|
|
[考研] 080500,材料學(xué)碩302分求調(diào)劑學(xué)校 +4 | 初識(shí)可樂(lè) 2026-03-14 | 5/250 |
|
|
[考研] 中科大材料專碩319求調(diào)劑 +3 | 孟鑫材料 2026-03-13 | 3/150 |
|
|
[考研] 0856材料與化工301求調(diào)劑 +5 | 奕束光 2026-03-13 | 5/250 |
|
|
[考研] 295求調(diào)劑 +3 | 小匕仔汁 2026-03-12 | 3/150 |
|