From: Hanna on
Hi,

I have an if sats with three statements. All statements are true one each but not simultaneously.

Here is the If statement with the three conditions:

if isnan(coups(ii,dd)) && isempty(mats(ii,dd))==0 && isnan(mats(ii,dd))==0;

I have tested both & and && but note of them is working. Any ideas?
From: Steven Lord on

"Hanna " <hannala(a)kth.se> wrote in message
news:hgaopr$o3g$1(a)fred.mathworks.com...
> Hi,
>
> I have an if sats with three statements. All statements are true one each
> but not simultaneously.
>
> Here is the If statement with the three conditions:
>
> if isnan(coups(ii,dd)) && isempty(mats(ii,dd))==0 &&
> isnan(mats(ii,dd))==0;
>
> I have tested both & and && but note of them is working. Any ideas?

Yes -- it sounds like you don't want this IF statement to be true only in
the case where the first condition AND the second condition AND the third
condition are all true simultaneously. If you're looking for this IF
statement to be true if the first condition OR the second condition OR the
third condition are true, use | or || instead of & or &&.

If that's not what you want to happen, describe in more detail SPECIFICALLY
what you want this IF statement to do and when you want the IF to be true.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


From: Florian on
"Hanna " <hannala(a)kth.se> wrote in message <hgaopr$o3g$1(a)fred.mathworks.com>...
> Hi,
>
> I have an if sats with three statements. All statements are true one each but not simultaneously.
>
> Here is the If statement with the three conditions:
>
> if isnan(coups(ii,dd)) && isempty(mats(ii,dd))==0 && isnan(mats(ii,dd))==0;
>
> I have tested both & and && but note of them is working. Any ideas?

In your code Matlab checks whether the condition of each statement is true, otherwise it breaks.

Is maybe "OR" the answer to your problem?

if isnan(coups(ii,dd)) || isempty(mats(ii,dd))==0 || isnan(mats(ii,dd))==0

Here Matlab will jump into the if statement as soon as it has found one of the statements to be true.
From: Jan Simon on
Dear Hanna!

> > if isnan(coups(ii,dd)) && isempty(mats(ii,dd))==0 && isnan(mats(ii,dd))==0;

Another idea:
isempty(mats(ii,dd))==0
is not meaningful, except if "mats" is a function. If so, calling it twice (for the check of emptiness and for NaN) might waste time.
If mats is an array or cell array, "mats(ii,dd)" must be non-empty.

Kind regards, Jan
From: Hanna on
Hi,
thanks for your answer. No that is not what I want. I want all statements to be true. I am going to be more specific: I have 2 matrices (coups and maturity) and I want that the empty elements of coups shall be filled with zeros when the emelents on the same place on mats are not empty and not a nan, hence the three statements.

It is inisde a loop and I believe that it might be a reason to my problem because when I loop through the two matrices it only works on the last row (i.e. the coups are filled with zeros when the above statements are true).

Here is the code:

for ii=length(coups(:,1));
for dd = 1:length(coups(1,:));
if isnan(coups(ii,dd)) && isempty(mats(ii,dd))==0 && isnan(mats(ii,dd))==0;
coups(ii,dd)=0;
end;
end;
end;

Hanna


"Florian" <flowwiththeflo(a)hotmail.com> wrote in message <hgapq7$1m0$1(a)fred.mathworks.com>...
> "Hanna " <hannala(a)kth.se> wrote in message <hgaopr$o3g$1(a)fred.mathworks.com>...
> > Hi,
> >
> > I have an if sats with three statements. All statements are true one each but not simultaneously.
> >
> > Here is the If statement with the three conditions:
> >
> > if isnan(coups(ii,dd)) && isempty(mats(ii,dd))==0 && isnan(mats(ii,dd))==0;
> >
> > I have tested both & and && but note of them is working. Any ideas?
>
> In your code Matlab checks whether the condition of each statement is true, otherwise it breaks.
>
> Is maybe "OR" the answer to your problem?
>
> if isnan(coups(ii,dd)) || isempty(mats(ii,dd))==0 || isnan(mats(ii,dd))==0
>
> Here Matlab will jump into the if statement as soon as it has found one of the statements to be true.