how to label strings in an array with an ID
6 次查看(过去 30 天)
显示 更早的评论
I have a array
StringID=['a',1;
'b',2;
'c',3]
and a table with a column with a bunch of strings that exactly match the strings in StringID.
tc=['c';
'b';
'c';
'a';
'c']
How can I make a column vector that identifies the strings with the number in StringID?
ans=[3;
2;
3;
1;
3]
I would like this to be scaleable to a few thousand rows and a StringID column of a couple hundred strings. I feel like there is a simple solution I'm not thinking of. I assume there is some combo of find and strcmp that I'm not thinking of. I could probably just do it with a loop, but I am trying to avoid that.
0 个评论
采纳的回答
更多回答(1 个)
madhan ravi
2020-8-3
T = cell2table(StringID(:, 2));
T.Properties.RowNames = StringID(:, 1);
Wanted = T{num2cell(tc), :}
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!