Asked by neda eskandari
on 18 Jun 2019 at 18:25

Hello Dears

i have the error that i mentioned in question and i do not know how i can solve it.

while (Lia2_One_Three ~= zeros(length(Lia2_One_Three),1) | Lia2_Two_Three ~= zeros(length(Lia2_Two_Three),1))

row_n2_three_step = randperm(length(area_2) / 2, n2_three_step_delayed_measurements) ;

Lia2_One_Three = ismember(row_n2_one_step, row_n2_three_step) ;

Lia2_Two_Three = ismember(row_n2_two_step, row_n2_three_step) ;

end

it seems that this error says that 'Lia2_One_Three ~= zeros(length(Lia2_One_Three)) ' and

' Lia2_Two_Three ~= zeros(length(Lia2_Two_Three))' should have same dimention. i just want to say that while the first condition or second condition is true, produce ' row_n2_three_step' again.

'Lia2_One_Three ' and ' Lia2_Two_Three ' are vectors with different dimentions.

Answer by James Tursa
on 18 Jun 2019 at 19:13

Edited by James Tursa
on 18 Jun 2019 at 19:15

Accepted Answer

Maybe this line:

while (Lia2_One_Three ~= zeros(length(Lia2_One_Three),1) | Lia2_Two_Three ~= zeros(length(Lia2_Two_Three),1))

could be this instead?

while ( any(Lia2_One_Three(:)) || any(Lia2_Two_Three(:)) )

I'm guessing a bit on what I think you want the test to do.

Note that the ~= and | operators are element-wise operators, which I am guessing is not what you really want to use here.

neda eskandari
on 18 Jun 2019 at 19:28

should not we write :

while ( any(Lia2_One_Three(:) ~= 0) || any(Lia2_Two_Three(:) ~= 0) )

James Tursa
on 18 Jun 2019 at 19:49

The any( ) functions tests for nonzeros, so the ~=0 part in your proposed code is redundant.

neda eskandari
on 18 Jun 2019 at 20:01

thanks a lot

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## KALYAN ACHARJYA (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/467764-how-to-solve-error-using-matrix-dimensions-must-agree#comment_716007

## neda eskandari (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/467764-how-to-solve-error-using-matrix-dimensions-must-agree#comment_716010

## neda eskandari (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/467764-how-to-solve-error-using-matrix-dimensions-must-agree#comment_716011

## neda eskandari (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/467764-how-to-solve-error-using-matrix-dimensions-must-agree#comment_716032

Sign in to comment.