How to correct the error Matlab says i've done?
Mostrar comentarios más antiguos
bsd Hello, here are the codes i'm using, Avodakodnew is the one i run, euler is needed for Avodakodnew. Here is the error i get when i try to run it:
>> Avodakodnew(5.5)
Subscripted assignment dimension mismatch.
Error in Avodakodnew (line 46) gu(i,j) = etha * ku(i,j) * diff ( u(i,j+1) - u(i,j), t ); %upper
What does this mean?
When i do >> ndims(gu), i get:
ans = 2
but if i ask for >> ndims(gu(i,j)), i get an error:
Subscript indices must either be real positive integers or logicals.
Anybody could help me to understand and correct that,please?
Respuesta aceptada
Más respuestas (6)
Andreas Goser
el 16 de Oct. de 2013
Editada: Andreas Goser
el 16 de Oct. de 2013
Could be multiple things in
etha * ku(i,j) * diff ( u(i,j+1) - u(i,j), t );
My gut feeling is you want to use .* instead of * in at least one of the operations.
2 comentarios
Andreas Goser
el 16 de Oct. de 2013
I can keep on guessing like you use i and j without assigning them first and MATLAB treats them as complex numbers, but first and foremost, in order to resolve this one needs code AND data.
The problem is concealed anywhere in this line. So split the line into its parts to find out, where the problem is:
c1 = u(i,j+1);
c2 = u(i,j);
c3 = c1 - c2;
c4 = diff(c3, t);
c5 = etha * ku(i,j);
c6 = c5 * c4;
gu(i,j) = c6;
Now find out which step fails.
4 comentarios
Andreas Goser
el 17 de Oct. de 2013
Jan, you are again too kind ;-)
Jan
el 17 de Oct. de 2013
But not kind enough to trust, that the users know how to debug their code.
Odelia
el 17 de Oct. de 2013
Image Analyst
el 18 de Oct. de 2013
I don't know what bsd means, but this will help http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/. That will definitely solve it but in case you don't want to do that, you can put these lines before that gu line:
whos i
whos j
whos c6
Siavash Kardar Tehran
el 17 de Oct. de 2013
0 votos
firt of all make sure when you're using "for" command the vectors start their indices from 1, I mean Matlab doesn't recognize gu(0) and it must start at gu(1);
also make sure u(i,j+1) doesn't exceed you matrix dimensions.
I hope this could help.
1 comentario
Odelia
el 17 de Oct. de 2013
Odelia
el 21 de Oct. de 2013
Odelia
el 6 de Nov. de 2013
0 votos
Categorías
Más información sobre Linear Algebra en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!