Error using >= Matrix dimensions must agree
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
NURFATIN NADIA
el 9 de Abr. de 2018
Comentada: NURFATIN NADIA
el 9 de Abr. de 2018
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?
0 comentarios
Respuesta aceptada
Walter Roberson
el 9 de Abr. de 2018
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 comentarios
Walter Roberson
el 9 de Abr. de 2018
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'
Más respuestas (0)
Ver también
Categorías
Más información sobre Special Characters en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!