Can't add matrix with same dimension, pulls error...
Afficher commentaires plus anciens
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???
Réponses (2)
per isakson
le 3 Jan 2013
Modifié(e) : per isakson
le 3 Jan 2013
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
le 3 Jan 2013
0 votes
People who use "sum" as the name of a variable always run into code problems when they do so.
Catégories
En savoir plus sur Debugging and Improving Code dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!