The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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: 18,038
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" <> wrote in message
> 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

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
To contact Technical Support use the Contact Us link on

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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.