Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


dpb
Posts:
8,364
Registered:
6/7/07


Re: using for loop to decide if is pass or fail
Posted:
Mar 8, 2013 9:14 AM


On 3/8/2013 5:56 AM, NatasaSI wrote: > "NatasaSI" wrote in message <khcfqq$qtl$1@newscl01ah.mathworks.com>... >> dpb <none@non.net> wrote in message <kham0u$rkq$1@speranza.aioe.org>... >> > On 3/7/2013 11:52 AM, dpb wrote: >> > ... >> > > > >> lbl={'PASS';'FAIL'} >> > > lbl = >> > > 'PASS' >> > > 'FAIL' >> > > >> x=rand(10,1)*10; >> > > >> disp([num2str(x) repmat(' ', [size(x)]) ... >> > > char(lbl(iswithin(x,4,8)+1))]) >> > ... >> > > Oops...sorry. Since I defined lbl as did, need to swap the logic >> of the > test to match...use >> > > disp([num2str(x) repmat(' ', [size(x)]) ... >> > > char(lbl(~iswithin(x,4,8)+1))]) >> > > instead. Or, of course, redefine lbl the other way 'round may make >> more > sense... >> > >  >> I wrote this: for k=1:length(frekvenca) >> x=matrika2(k,1); >> disp([num2str(x) repmat(' ', [size(x)]) >> char(lbl(iswithin(x,limitA,limitB)))]) >> end >> >> and the output is like: >> 0.57136 PASS >> 0.3472 PASS >> 0.25832 PASS >> 0.27942 PASS >> 0.99918 0.040682 PASS >> 0.55887 PASS >> 0.14334 PASS >> without FAIL (fail have to be where is blank space in 2nd column) >> and also alignment is strange. >> Where i made a mistake? > I found the mistake. I forgot '+1' in > char(lbl(iswithin(x,limitA,limitB)))]). > > Now i have the result that i need. How can i conclude the test like this: > if all elements are PASS than write 'Test: PASS', otherwise 'Test:FAIL'? > > for m=1:length(frekvenca) > if matrika2(m,2)= 'PASS' % PROBLEM???? > disp('Test: PASS') > else disp('Test: FAIL') > end > end
Again, the Matlab way...
if all(iswithin(x,Lo,Hi)) disp('Test: PASS') else disp('Test: FAIL') end
Don't need any loops...
The incorporation of the vectorized operations within Matlab is a prime reason for there to even _be_ a MatlabLearning to utilize the capabilities will serve well in the long run. (If don't, next thing will be you're posting here asking how to speed up a long computation... :) )



Date

Subject

Author

3/8/13


dpb

3/9/13


dpb

3/19/13


dpb


