From: silversurfer on 14 Jun 2010 00:36 %%%% why the program execute only else part of if loop .....???????????????? t=18; while t<=23 if (t==20 || t==21 || t==22) J_stim=1 t else J_stim=0 t end t=t+0.1; end if run this progam in matlab 7.5 then the output is J_stim = 0 t = 18 J_stim = 0 t = 18.1000 J_stim = 0 t = 18.2000 J_stim = 0 t = 18.3000 J_stim = 0 t = 18.4000 J_stim = 0 t = 18.5000 J_stim = 0 t = 18.6000 J_stim = 0 t = 18.7000 J_stim = 0 t = 18.8000 J_stim = 0 t = 18.9000 J_stim = 0 t = 19.0000 J_stim = 0 t = 19.1000 J_stim = 0 t = 19.2000 J_stim = 0 t = 19.3000 J_stim = 0 t = 19.4000 J_stim = 0 t = 19.5000 J_stim = 0 t = 19.6000 J_stim = 0 t = 19.7000 J_stim = 0 t = 19.8000 J_stim = 0 t = 19.9000 J_stim = 0 t = 20.0000 J_stim = 0 t = 20.1000 J_stim = 0 t = 20.2000 J_stim = 0 t = 20.3000 J_stim = 0 t = 20.4000 J_stim = 0 t = 20.5000 J_stim = 0 t = 20.6000 J_stim = 0 t = 20.7000 J_stim = 0 t = 20.8000 J_stim = 0 t = 20.9000 J_stim = 0 t = 21.0000 J_stim = 0 t = 21.1000 J_stim = 0 t = 21.2000 J_stim = 0 t = 21.3000 J_stim = 0 t = 21.4000 J_stim = 0 t = 21.5000 J_stim = 0 t = 21.6000 J_stim = 0 t = 21.7000 J_stim = 0 t = 21.8000 J_stim = 0 t = 21.9000 J_stim = 0 t = 22.0000 J_stim = 0 t = 22.1000 J_stim = 0 t = 22.2000 J_stim = 0 t = 22.3000 J_stim = 0 t = 22.4000 J_stim = 0 t = 22.5000 J_stim = 0 t = 22.6000 J_stim = 0 t = 22.7000 J_stim = 0 t = 22.8000 J_stim = 0 t = 22.9000 it is not executing for t=23 and for t=20,21Or 22 it is not going into the if part it alway execute else part is some one has a solution please mail me.
From: dpb on 14 Jun 2010 00:52 silversurfer wrote: > %%%% why the program execute only else part of if > loop .....???????????????? > t=18; > while t<=23 > if (t==20 || t==21 || t==22) > J_stim=1 .... > t=t+0.1; > end > if run this progam in matlab 7.5 .... > it is not executing for t=23 > and for t=20,21Or 22 it is not going into the if part it alway execute > else part is some one has a solution please mail me. See the Matlab FAQ 6.1 at <http://matlabwiki.mathworks.com/MATLAB_FAQ#Why_is_0.3-0.2-0.1_not_equal_to_zero_.28or_similar.29.3F> Short answer is "floating point is not exact" If you need a specific number of iterations or an exact comparison, avoid floating point increments in loop counters or equalities. --
|
Pages: 1 Prev: Matlab's Simulink error message Next: How To find a WHOLE row in another matrix |