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
2013년 1월 3일
편집: per isakson
2013년 1월 3일
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
2013년 1월 3일
0 개 추천
People who use "sum" as the name of a variable always run into code problems when they do so.
카테고리
도움말 센터 및 File Exchange에서 Debugging and Improving Code에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!