Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: using for loop to decide if is pass or fail
Replies: 5   Last Post: Mar 19, 2013 1:49 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
dpb

Posts: 8,288
Registered: 6/7/07
Re: using for loop to decide if is pass or fail
Posted: Mar 8, 2013 9:14 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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 Matlab--Learning 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... :) )

--



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.