Problem with find string in array
이전 댓글 표시
Hello, i try to find mark 'bmw' in Mfg table(carbig.mat).I want to create new logic table with 1 (if string exist) or 0 to others string.
>> idx = ismember((Mfg(:,1:6)=='bmw'),[1,1,1,1,1,1],'rows')
But i have this mistake:
Error using ==
Matrix dimensions must agree.
It's my workspace:

댓글 수: 4
Stephen23
2020년 3월 20일
First convert the character matrix to a cell array of strings or to a string array without leading/trailing space characters and then use strcmpi.
madhan ravi
2020년 3월 20일
Would you attach a sample file ?
the cyclist
2020년 3월 20일
@madhan, if you type
load carbig.mat
you'll have the data. It is a file used for examples in the documentation.
madhan ravi
2020년 3월 20일
Thank you the cyclist.
채택된 답변
추가 답변 (1개)
the cyclist
2020년 3월 20일
contains(cellstr(Mfg),'bmw')
댓글 수: 5
Kostiantyn Voskoboinik
2020년 3월 20일
the cyclist
2020년 3월 20일
Do you have an older version of MATLAB? The contains function was introduced in R2016b.
Kostiantyn Voskoboinik
2020년 3월 20일
the cyclist
2020년 3월 20일
This is more awkward, but will work
not(cellfun(@isempty,strfind(cellstr(Mfg),'bmw')))
I expect there is something more elegant.
Kostiantyn Voskoboinik
2020년 3월 21일
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!