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,053
Registered: 6/7/07
Re: using for loop to decide if is pass or fail
Posted: Mar 19, 2013 1:49 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 3/19/2013 10:28 AM, NatasaSI wrote:
...

>> 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'};
>> flg=iswithin(x,lo,hi);
>> disp([num2str(x) repmat(' ', [size(x)]) char(lbl(flg+1))])
>> disp(['TEST ' char(lbl(all(flg)+1))])
>>

...

> I try to do insert this:
>
> if all(iswithin(x,limitA,limitB))
> disp('Test: PASS')
> else
> disp('Test: FAIL')
> end
>
> and this:
>
> lbl = {'FAIL';'PASS'};
> flg=iswithin(x,limitA,limitB);
> disp([num2str(x) repmat(' ', [size(x)]) char(lbl(flg+1))])
> disp(['TEST ' char(lbl(all(flg)+1))])
>
> so my final code is like this:
> limitA= 0.996
> limitB= 0.0013
> lbl={'FAIL';'PASS'};
>
> for k=1:length(frekvenca)
> x=matrika2(k,1);
> disp([num2str(x) repmat(' ', [size(x)]) ...
> char(lbl(iswithin(x,limitA,limitB)+1))])
> end
>
>
> % if all(iswithin(x,limitA,limitB))
> % disp('Test: PASS')
> % else
> % disp('Test: FAIL')
> % end
>
> flg=iswithin(x,limitA,limitB);
> disp([num2str(x) repmat(' ', [size(x)]) char(lbl(flg+1))])
> disp(['TEST ' char(lbl(all(flg)+1))])
>
> The output is like:
> 0.25832 PASS
> 0.27942 PASS
> 0.99918 FAIL

...
> 0.11005 PASS
> 0.29027 PASS
> TEST PASS
> Even if there is one FAIL the result is TEST PASS. Where is the problem?
> Thanks for help


You seem not to be paying any attention here, unfortunately... :(

You don't need the loop (and it's getting in the way) -- use the array
directly as shown before. If the upper limit length(frekvenca) isn't
the same as size(matrika2,2) (which would be the more logical value to
use for the loop bound it would seem given the code but sometimes one
doesn't want to process the entire array, granted, so if that's the case
then ignore this sidebar) then use matrika2(1:frekvenca,1) in the
vectorized solution.

The reason you're getting 'PASS' for the last case is that you're
testing the value of x which is the single value last processed by the
loop _NOT_ the full complement and since the last individual case is a
success then it's going to be when it's tested again. If the order were
such that the last element were to not pass then you would get 'FAIL'
for every set of data instead no matter what set of data it were and the
fact the answer appears correct would simply be happenstance. For that
reason you were lucky the case data was as it is; you caught the error
in having the wrong result.

In my previous examples I used "x" as a shorthand for your subarray on
the assumption you could take that and apply it to your problem. I'll
leave you to do that.

--




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.