Finding a column with specific text

7 次查看(过去 30 天)
I am trying to create a function that takes a array of characters and finds the first column that has a specific input. It seems to work however when I ask have cells with multiple characters an error message saying matrix dimensions must agree. Not sure what I am doing wrong. Any suggestions?

采纳的回答

Star Strider
Star Strider 2021-2-15
I have no clear idea of what the exact problem is, however using strfind or strcmp (or strcmpi) instead of the logical operation with ‘==’ could do what you want.
  3 个评论
Adam Danz
Adam Danz 2021-2-15
编辑:Adam Danz 2021-2-15
strcmp/strcmpi returns the index number.
If your array is 1D (vector) then you're problem is solved.
If your array is >1D you can use ind2sub to get the column number.
ind = strcmpi(YourArray, subStr);
[~, col] = ind2sub(size(YourArray),find(ind));
Star Strider
Star Strider 2021-2-15
BENJAMIN BUCHDA — Als always, my pleasure!
Adam Danz — Thank you.
.

请先登录,再进行评论。

更多回答(0 个)

类别

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