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 ]

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

On 3/8/2013 8:14 AM, dpb wrote:
> On 3/8/2013 5:56 AM, NatasaSI wrote:

>> 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'?


> Again, the Matlab way...
> if all(iswithin(x,Lo,Hi))
> disp('Test: PASS')
> else
> disp('Test: FAIL')
> end
> Don't need any loops...


And, of course, you can eliminate the if...else...end clause easily as well.

disp(['TEST ' char(lbl(all(iswithin(x,lo,hi))+1))])

To avoid the overhead of calling iswithin() twice, save the resulting
logical vector the first time and use it in place of the explicit call...

lbl = {'FAIL';'PASS'};
disp([num2str(x) repmat(' ', [size(x)]) char(lbl(flg+1))])
disp(['TEST ' char(lbl(all(flg)+1))])

NB: One has a choice -- one can eliminate the cast to char() if one
makes the label array a character array instead of cell strings, but
then the subscripting has to use the 2nd dimension ':' to get the full
string, not just the first character. It seems awkward to me there
isn't an overloaded horzcat for cell strings that "just works"...


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

[Privacy Policy] [Terms of Use]

© The Math Forum 1994-2015. All Rights Reserved.