| 查看: 1616 | 回復(fù): 10 | ||
ysu_Amanda金蟲 (著名寫手)
|
[求助]
實(shí)在是看不出這段matlab程序里哪里出錯了,請大家?guī)兔纯矗?
|
|
for L=1:c for i=1:Tn(L) if L==1 sum_index=i; else sum_index=sum(Tn(1:L-1))+i; end y=D(:,sum_index); if sum_index==1 re_index=2:n; elseif sum_index==n re_index=1:n-1; else re_index=[1:sum_index-1,sum_index+1:n]; end end end 如上第一次循環(huán)中sum_index應(yīng)該為1,re_index應(yīng)該為2:n.但一運(yùn)行就出錯顯示re_index根本沒被賦值,是空的。這是怎么回事,我看了好多遍程序?qū)嵲诳床怀瞿睦镉绣e誤,希望大家多幫忙! |

新蟲 (初入文壇)
金蟲 (著名寫手)

至尊木蟲 (著名寫手)
驃騎將軍
|
if有else塊,re_index肯定會被賦值,也就是下面這行肯定會被運(yùn)行到 re_index=[1:sum_index-1,sum_index+1:n]; 但是你說沒有值,在這行前面加2句: sum_index n 然后運(yùn)行看看輸出什么值. 因?yàn)殡m然在matlab中a:b是生成a到b的序列,但是如果b<a,就會生成空矩陣. |

木蟲 (正式寫手)
|
從Debug 單步跟蹤的結(jié)果來看,第一次運(yùn)行的結(jié)果是對的。 re_index的值是[2:n]。 示例如下: 不知道D的用途,將其屏蔽,本函數(shù)簡化成一個加法函數(shù)。 function [sum_index, re_index]=t1(Tn,c) % This is a test function n=length(Tn); if c>=n c=n; end for L=1:c for i=1:Tn(L) if L==1 sum_index=i; else sum_index=sum(Tn(1:L-1))+i; end % y=D(:,sum_index); if sum_index==1 re_index=2:n; elseif sum_index==n re_index=1:n-1; else re_index=[1:sum_index-1,sum_index+1:n]; end end end end 使用 x=[5,10,15,20,25,30] c=6, 計算[ssx,sssc]=t1(x,c),取得的結(jié)果是 105, 以及 1-104的輸出。 單步跟蹤正常。 |
|
if L==1 sum_index=i else sum_index=sum(Tn(1:L-1))+i end 這一句,是對你的Tn的加和,這個值會不會超過n使得 if sum_index==1 re_index=2:n elseif sum_index==n re_index=1:n-1 else re_index=[1:sum_index-1,sum_index+1:n] end 前兩個判斷返回值為0,進(jìn)入else 但是sum_index+1:n這個矩陣是個空矩陣,因?yàn)榍懊姹群竺娲蟆?br /> 從程序上我只能理解到這個位置 意見作為參考,本人不是學(xué)語言的。 |

金蟲 (小有名氣)
金蟲 (小有名氣)
金蟲 (著名寫手)

|
本帖內(nèi)容被屏蔽 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研]
|
酥酥魚.. 2026-03-21 | 3/150 |
|
|---|---|---|---|---|
|
[考研] 280求調(diào)劑 +11 | 咕嚕曉曉 2026-03-18 | 12/600 |
|
|
[考研] 廣西大學(xué)材料導(dǎo)師推薦 +3 | 夏夏夏小正 2026-03-17 | 5/250 |
|
|
[考研] 297求調(diào)劑 +3 | 喜歡還是不甘心 2026-03-20 | 3/150 |
|
|
[考研] 316求調(diào)劑 +6 | 梁茜雯 2026-03-19 | 6/300 |
|
|
[考研] 機(jī)械專碩299求調(diào)劑至材料 +3 | kkcoco25 2026-03-16 | 4/200 |
|
|
[考研] 307求調(diào)劑 +3 | wyyyqx 2026-03-17 | 3/150 |
|
|
[考研] 332求調(diào)劑 +4 | ydfyh 2026-03-17 | 4/200 |
|
|
[考研] 材料 336 求調(diào)劑 +3 | An@. 2026-03-18 | 4/200 |
|
|
[考研] 一志愿武漢理工材料工程專碩調(diào)劑 +9 | Doleres 2026-03-19 | 9/450 |
|
|
[考研] 287求調(diào)劑 +7 | 晨昏線與星海 2026-03-19 | 8/400 |
|
|
[考研] 0856調(diào)劑,是學(xué)校就去 +8 | sllhht 2026-03-19 | 9/450 |
|
|
[考研] 081700化工學(xué)碩調(diào)劑 +3 | 【1】 2026-03-16 | 3/150 |
|
|
[考博] 申博26年 +3 | 八6八68 2026-03-19 | 3/150 |
|
|
[考研] 286求調(diào)劑 +6 | lemonzzn 2026-03-16 | 10/500 |
|
|
[考研] 0703化學(xué)調(diào)劑 +5 | pupcoco 2026-03-17 | 8/400 |
|
|
[考研] 材料,紡織,生物(0856、0710),化學(xué)招生啦 +3 | Eember. 2026-03-17 | 9/450 |
|
|
[考研] 334求調(diào)劑 +3 | 志存高遠(yuǎn)意在機(jī)?/a> 2026-03-16 | 3/150 |
|
|
[考研] 283求調(diào)劑 +3 | 聽風(fēng)就是雨; 2026-03-16 | 3/150 |
|
|
[考研] 333求調(diào)劑 +3 | 文思客 2026-03-16 | 7/350 |
|