Search All of the Math Forum:

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

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

 Messages: [ Previous | Next ]
 Steven Lord Posts: 18,038 Registered: 12/7/04
Re: which if expression work
Posted: Jan 25, 2013 9:21 AM

"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