Find the cell which is containing a string
1 次查看(过去 30 天)
显示 更早的评论
hi guys, i have the below array:
A={'Dimension','Weight','Qty','Thk','Total Price'};
now I want to find out which cell (Row and Col number) has the string 'Price' in it, and the answer is row=1, col=5.
i dont know how to find that cell when i have only a part of the whole string in a cell,
please help me what to do, thnx a lot
0 个评论
采纳的回答
Stephan
2020-11-16
A={'Dimension','Weight','Qty','Thk','Total Price'};
[r,c] = find(contains(A,'Price'))
更多回答(2 个)
Ameer Hamza
2020-11-16
Another solution using regexpi() which takes care of the letter-case too.
[r, c] = find(~cellfun(@isempty, regexpi(A, 'price')))
3 个评论
Ameer Hamza
2020-11-17
编辑:Ameer Hamza
2020-11-17
Yes, I meant that it works for all cases, wether you use 'price', 'Price', 'pRiCe'. regexpi() does not care about the case.
Setsuna Yuuki.
2020-11-16
A={'Dimension','Weight','Qty','Thk','Total Price'};
b = strfind(A,'Price')
for n=1:length(b)
if (~isnan(b{n}))
break;
end
end
fprintf("row 1, column %i \n",n)
另请参阅
类别
在 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!