the command after "if" not work after awhile
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
mohammad gudarzi
el 23 de Mayo de 2019
Comentada: mohammad gudarzi
el 23 de Mayo de 2019
the "counter"=1 at start, the command under if work until t==8 but after that it's looklike "if" not working beside that "t" continue untill 200.
thanks
if t==(1*counter)
filename = 'y.xlsx';
filename1= 'V.xlsx';
filename2= 'Q.xlsx';
A=double(yp);
C=double(vp);
D=double(Qp);
for i=1:16
maty(counter,i)=A(1,i);
matQ(counter,i)=D(1,i);
matv(counter,i)=C(1,i);
my{counter,i}=[A(1,i)];
mv{counter,i}=[C(1,i)];
mq{counter,i}=[D(1,i)];
end
counter=counter+1;
end
4 comentarios
Geoff Hayes
el 23 de Mayo de 2019
What are you expecting to happen with this code?
if t==0:1:200
plot(X0,yp)
end
Do you really mean to compare t to an array of values from 0-200?
Respuesta aceptada
the cyclist
el 23 de Mayo de 2019
My best guess here is that you are running up against the limitations of floating point computation. For example, try putting this expression into MATLAB:
6*0.01 == (0.01+0.01+0.01+0.01+0.01+0.01)
You will find that the result is false (logical 0). This is probably unexpected by you.
Then try
6*0.01 - (0.01+0.01+0.01+0.01+0.01+0.01)
and you will see that the result is a number of order 1.e-18 (very tiny but not zero).
I suggest that you read this documentation page about floating point representation. There are also many, many answers here that talk about this issue. Be aware that this is not some kind of MATLAB error.
I also happened to notice that you have this line in your code:
if t==0:1:200
...
end
I'm not sure what you are expecting to happen there, but you will only enter that loop is t is equal to the vector [0 1 2 ... 199 200].
Más respuestas (0)
Ver también
Categorías
Más información sobre Function Creation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!