String matching and data extract

조회 수: 1 (최근 30일)
Hamza Karakurt
Hamza Karakurt 2016년 5월 18일
답변: Guillaume 2016년 5월 18일
Hello, I am trying to match two string arrays and extract a matrix of datas by using the results. When I try to do, I have this error. "Improper assignment with rectangular empty matrix" My code is
for i=1:length(A)
I = strmatch(A(i), B, 'exact');
unique_data_(i) = max(Data(I,:));
end
How can I do my work?
Thank you, Have a good day

답변 (1개)

Guillaume
Guillaume 2016년 5월 18일
I've never seen that exact error message (which version of matlab?) but your code is certainly going to produce an error if there is no match for an element of A since you'll try to assign empty to a scalar. And if there is more than one match and Data has more than one column, max(Data(I, :) is going to return a vector, which will also fail to be assigned to a scalar.
How to fix that depends on what you want to do in either case.
Also matlab tells me that "strmatch is not recommended. [...] To find an exact match for a string, use strcmp." Certainly, the way you're using it strcmp would actually be better.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by