Error using >= Matrix dimensions must agree

I'm trying this code:
status = zeros(0,length(centroidA));
for i=1:length(centroidA)
if ED1_cell{i} >= ED2_cell{i}
status(i) = {'embedded'};
else
status(i) = {'malapposed'};
end
end
and here is the error: Error using >= Matrix dimensions must agree.
CentroidA, ED1_cell, ED2_cell are all 11x1 cell. How?

 Accepted Answer

The question at the moment is not about the size of the cell arrays: it is about the size of the content of the cell arrays. For the >= operation to work, the data in the two cells must either be the same size or one of the two must be a scalar.
Watch out especially for character vectors: you can compare them using >= but only when the two are exactly the same length. This is different than the newer string() scalar objects, which can be compared with >= even if they are different lengths.

3 Comments

Oh! I've just checked it,one is 1x7 char and the other one is 1x6 char. How can I set length of one of them so they can both be the same?
compare_str = @(s1, s2, n) s1(1:n) >= s2(1:n);
compare_str = @(s1, s2) compare_ge(s1, s2, min(length(s1),length(s2)));
Note that this code says that if two strings are the same up to the length of the shorter then the two are to be compared as equal. Some people would argue that a shorter string being compared to a longer string that matches up to the length of the shorter string should be considered to be less than the longer string. For example, comparing 'go' to 'gone' in that order, some people would argue that 'go' should be considered to be less than 'gone'

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!