samedi 4 mars 2017

MATLAB if function with &, Matrix dimensions must agree error

My code works when I type

if size(k)==size(k1) 
    disp('They match');

or

if k-k1==0
    disp('They match');

but if I type in two conditions at the same time like this,

if size(k)==size(k1) & k-k1==0
    disp('They match');

I get an error saying

"Matrix dimensions must agree.

Error in practice (line 32) if size(k)==size(k1) & k-k1==0"

FYI, the dimension of k and k1 are both 1x717 double. I checked it.

So I want to make an 'if' statement that includes two conditions at the same time, but I am experiencing an error. Two && won't work cuz two && is for scalars, but my k and k1 are vectors.

Any help will be appreciated

Aucun commentaire:

Enregistrer un commentaire