Search code examples
matlabmatrixerror-handlingdimensions

Error using == Matrix dimensions must agree


I've been working on an assignment. One part of the code I've been working on doesn't work. There is a file called txt that is a 12x1 cell array with 12 words all in a column, and the code needs to call each name one by one, and do some calculations. I need the code in line 30 to check if the cell contains the word shmoop, if it does, than it excecutes the code, otherwise it does the other code. How do I check if the array is the word shmoop! THANK YOU!

Error using == Matrix dimensions must agree.

Error in asd (line 30) if lanes == 'shmoop';

for c = 2:d
lanes = txt{c,1};
if lanes == 'shmoop';
    Monstershit{d,2}=paces;
    Monstershit{d,3}=pacez;
    Monstershit{d,4}=pacea;
else
    Monstershit{d,2}=pacev;
    Monstershit{d,3}=peace;
    Monstershit{d,4}=pasem;
end

end


Solution

  • Comparing strings with == only works if the dimensions of the two objects are the same. In general, you should use strcmp instead.