Error using >= Matrix dimensions must agree

조회 수: 6 (최근 30일)
NURFATIN NADIA
NURFATIN NADIA 2018년 4월 9일
댓글: NURFATIN NADIA 2018년 4월 9일
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?

채택된 답변

Walter Roberson
Walter Roberson 2018년 4월 9일
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
Walter Roberson
Walter Roberson 2018년 4월 9일
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'
NURFATIN NADIA
NURFATIN NADIA 2018년 4월 9일
thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Special Characters에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by