Re: Trouble using the OR operator within a 'while' loop...
- From: matlab_rookie <matthewdodds86@xxxxxxxxxxxxx>
- Date: Mon, 31 Mar 2008 07:57:14 -0700 (PDT)
On Mar 31, 3:27 pm, ImageAnalyst <imageanal...@xxxxxxxxxxxxxx> wrote:
On Mar 31, 9:39 am, matlab_rookie <matthewdodd...@xxxxxxxxxxxxx>
wrote:
Hi everyone,
I've been having some problems using a while loop in my code. I get
the error:
??? Error using ==> or
Matrix dimensions must agree.
Error in ==> letstryagain2 at 101
while totalconcentration < 50000 | totalconcentration2 < 50000
totalconcentration and totalconcentration2 are both within the while
loop, and generally totalconcentration2 is one step longer than
totalconcentration, but i'm not sure why. I just can't work out how
to solve the problem! Whats happening at the moment, is that the while
loop only stops when the condition before the OR operator, but not for
the latter condition.
Any ideas would be greatfully accepted! As you can probably tell from
my name...i'm a bit of a newby at this!
----------------------------------------------------------------------
matlab_rookie :
I'm betting either totalconcentration or totalconcentration2 is a
multidimensional array. That means that
totalconcentration < 50000
is also a multidimensional array. If the dimensions of
totalconcentration and totalconcentration2 are not the same, you will
get that error.
But the main problem is that you're trying to create a NEW array by
OR'ing the two together when what I think you really want is the
logical OR operator ||.
Check out the following code:
clc;
a4 = magic(4)
a5 = magic(5)
b4 = a4 < 8 % 4 by 4 array.
b5 = a5 < 12 % 5 by 5 array.
b4ORedWithb5 = b4 | b5
logicalOrAB = b4 || b5;
Regards,
ImageAnalyst
Hi, thanks for getting back to me. I tried what you both suggested,
but i'm still having problems. When using the totalconcentration(end)
suggestion...the simulation just ran forever and didnt stop. Possibly
because i hadn't defined what the (end) was?
And when trying using the || operator, i get the error..."??? Operands
to the || and && operators must be convertible to logical scalar
values."
totalconcentration and totalconcentration2 are both 1 x k arrays. But
k seems to be one larger for totalconcentration2...
.
- Follow-Ups:
- Re: Trouble using the OR operator within a 'while' loop...
- From: ImageAnalyst
- Re: Trouble using the OR operator within a 'while' loop...
- References:
- Trouble using the OR operator within a 'while' loop...
- From: matlab_rookie
- Re: Trouble using the OR operator within a 'while' loop...
- From: ImageAnalyst
- Trouble using the OR operator within a 'while' loop...
- Prev by Date: Re: text file update
- Next by Date: Belligerent uitable Prop. Inspector in GUIDE
- Previous by thread: Re: Trouble using the OR operator within a 'while' loop...
- Next by thread: Re: Trouble using the OR operator within a 'while' loop...
- Index(es):
Relevant Pages
|