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: which if expression work
Replies: 1   Last Post: Jan 25, 2013 9:21 AM

Advanced Search

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

Posts: 17,944
Registered: 12/7/04
Re: which if expression work
Posted: Jan 25, 2013 9:21 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply



"mustafa senkaya" <mustafasenkaya@gmail.com> wrote in message
news:kdtp0r$id0$1@newscl01ah.mathworks.com...
> Hi all,
> i have script;
>
> if (ch_mis<tol_d)|(rms_vs_change < tol_m) |(best_mis <= ht)
> m_fin=m_inv;
> data_fin=data_inv(:, best_index(i+1));
> ['Solution converged with rms error: ', num2str(best_mis(i+1))]
> break
> end
>
> i wonder that, is there any way to know which statement works or provides
> in if command; first, second or third?


As written? No, not without reevaluating the condition. All you know is that
at least one of those conditions was satisfied. If it's important to know
which one(s) I would precompute the results:

condition1 = (ch_mis<tol_d);
condition2 = (rms_vs_change < tol_m);
condition3 = (best_mis <= ht);
if condition1 || condition2 || condition3 % Assuming all those are scalars
% In here you can check the contents of condition1, condition2, or
condition3.
end

Note that this WILL evaluate all the conditions while the first may not due
to the short-circuiting behavior of | when used in an IF statement.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com




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.