MATLAB Answers

Problem with find string in array

5 views (last 30 days)
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 Comments

Show 1 older comment
madhan ravi
madhan ravi on 20 Mar 2020
Would you attach a sample file ?
the cyclist
the cyclist on 20 Mar 2020
@madhan, if you type
load carbig.mat
you'll have the data. It is a file used for examples in the documentation.
madhan ravi
madhan ravi on 20 Mar 2020
Thank you the cyclist.

Sign in to comment.

Accepted Answer

madhan ravi
madhan ravi on 20 Mar 2020
Wanted = ismember(cellstr(Mfg),'bmw')

  1 Comment

Sign in to comment.

More Answers (1)

the cyclist
the cyclist on 20 Mar 2020
contains(cellstr(Mfg),'bmw')

  5 Comments

Show 2 older comments
the cyclist
the cyclist on 20 Mar 2020
This is more awkward, but will work
not(cellfun(@isempty,strfind(cellstr(Mfg),'bmw')))
I expect there is something more elegant.

Sign in to comment.

Sign in to answer this question.


Translated by