Condition if on the elements of matrix in two For loop doesn't work
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Dear all, I posted my problem there is some days ago but I'didn't recieve a right answer. In my code, I use two for loops with some conditions on the elements of the matrix. thre is no error using two loops and the size of different parametrs and that of the matrix is right. But when I compare the rsults to that obtained using one for loop, I realised that the condition if doesn't work.
Any one has an idea!!!!
Thank you in advance. Adam
5 comentarios
Jan
el 21 de Ag. de 2012
Please, adam, omit the "clear all" because it is a frequently used, but always useless waste of time. If you are really convinced that a brute clearing helps you for any reasons, use "clear variables".
Respuestas (3)
Azzi Abdelmalek
el 21 de Ag. de 2012
Editada: Azzi Abdelmalek
el 21 de Ag. de 2012
if i have understood whaat is your problem
- you are using if elseif elseif ....
- if the condition 1 is satisfied the other conditions will be skiped even they are true
- instead using if elseif elseif ... use
if exp1
%do
end
if exp2
%do
end
12 comentarios
Jan
el 21 de Ag. de 2012
Editada: Jan
el 21 de Ag. de 2012
r=0:dr:5;
rr=r';
...
for l=1:length(xxb);
...
for m=1:length(rr)
if R<rr
Now rr is a vector, but R is a scalar. Then if R < rr is executed implicitly as
if all(R < rr) && ~isempty( R) && ~isempty(rr)
I guess you want something like if R < rr(m).
4 comentarios
Jan
el 21 de Ag. de 2012
Editada: Jan
el 21 de Ag. de 2012
I repeat my suggestion to use the debugger by your own to find the cause of the differences. I still do not see a chance for us to distinguish correct from incorrect values, but you obviously have a method to do so.
And I recommend again to omit the useless but time consuming "clear all".
Ver también
Categorías
Más información sobre Particle & Nuclear Physics en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!