Can't add matrix with same dimension, pulls error...

so far, i have this code
function polamodel=meanmodel(pola)
[lod,hid] = wavefilter('jpeg9.7','d');
pass=1;
[cc,sc]=wavedec2(pola{1}{2}{1},pass,lod,hid);
s=size(cc);
for i=1:62
sum=zeros(1,s(2));
for j=1:30
[c,s]=wavedec2(pola{i}{2}{j},pass,lod,hid);
sum=sum+c;
end
pola{i}{3}=sum ./30;
end
polamodel=pola;
end
but then i have this error :
??? Error using ==> plus
Matrix dimensions must agree.
Error in ==> meanmodel at 15
sum=sum+c;
Error in ==> main at 52
pola=meanmodel(pola);
that telling me the line sum=sum+c have an error in it. It's very weird because I'm very sure variable c and sum have a same dimension (I tried to figure it out with size(c) and size(sum)). I assume the error comes with variable c.
Anybody have an idea???

回答 (2 件)

per isakson
per isakson 2013 年 1 月 3 日
編集済み: per isakson 2013 年 1 月 3 日

0 投票

Use the debugger. Execute in the command window
dbstop if error
and run your function
polamodel=meanmodel(pola);
Matlab will stop at line 15. Inspect the values of the variables i, j, c.
There are buttons in the toolbar to operate the debugger.
Return here if you don't find the reason for the error.
PS. I'm not so sure!
Walter Roberson
Walter Roberson 2013 年 1 月 3 日

0 投票

People who use "sum" as the name of a variable always run into code problems when they do so.

カテゴリ

ヘルプ センター および File ExchangeDebugging and Improving Code についてさらに検索

製品

質問済み:

2013 年 1 月 3 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by