| 6 | 1/1 | 返回列表 |
| 查看: 698 | 回復(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)問各位大神,這樣的問題該怎么解決?非常感謝 |

木蟲 (著名寫手)


木蟲 (著名寫手)

|
大神,我按上面的方法做了,但是又出現(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ò)誤怎么解決啊?非常感激! |

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

| 6 | 1/1 | 返回列表 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 294求調(diào)劑材料與化工專碩 +12 | 陌の森林 2026-03-18 | 12/600 |
|
|---|---|---|---|---|
|
[考研] 招收調(diào)劑碩士 +4 | lidianxing 2026-03-19 | 10/500 |
|
|
[考研]
|
.6lL 2026-03-18 | 6/300 |
|
|
[考研] 材料專碩274一志愿陜西師范大學(xué)求調(diào)劑 +8 | 薛云鵬 2026-03-13 | 8/400 |
|
|
[考研] 307求調(diào)劑 +6 | 冷笙123 2026-03-17 | 6/300 |
|
|
[考研] 求調(diào)劑 +3 | Mqqqqqq 2026-03-19 | 3/150 |
|
|
[考研] 一志愿南昌大學(xué),327分,材料與化工085600 +3 | Ncdx123456 2026-03-19 | 3/150 |
|
|
[教師之家] 焦慮 +9 | 水冰月月野兔 2026-03-13 | 13/650 |
|
|
[考研] 材料專業(yè)求調(diào)劑 +5 | hanamiko 2026-03-18 | 5/250 |
|
|
[考研] 08工科 320總分 求調(diào)劑 +5 | 梨花珞晚風(fēng) 2026-03-17 | 5/250 |
|
|
[考研] 0703化學(xué)求調(diào)劑 總分331 +3 | ZY-05 2026-03-13 | 3/150 |
|
|
[考研] 265求調(diào)劑 +3 | 梁梁校校 2026-03-17 | 3/150 |
|
|
[考研] 268求調(diào)劑 +8 | 一定有學(xué)上- 2026-03-14 | 9/450 |
|
|
[考研] 332求調(diào)劑 +6 | Zz版 2026-03-13 | 6/300 |
|
|
[考研] 東南大學(xué)364求調(diào)劑 +5 | JasonYuiui 2026-03-15 | 5/250 |
|
|
[考研] 0854控制工程 359求調(diào)劑 可跨專業(yè) +3 | 626776879 2026-03-14 | 9/450 |
|
|
[考研] 一志愿211 0703方向310分求調(diào)劑 +3 | 努力奮斗112 2026-03-15 | 3/150 |
|
|
[考研] 0703一志愿211 285分求調(diào)劑 +5 | ly3471z 2026-03-13 | 5/250 |
|
|
[考研] 22408總分284求調(diào)劑 +3 | InAspic 2026-03-13 | 3/150 |
|
|
[考研] 308求調(diào)劑 +3 | 是Lupa啊 2026-03-12 | 3/150 |
|