Find the cell which is containing a string

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

 採用された回答

Stephan
Stephan 2020 年 11 月 16 日

1 投票

A={'Dimension','Weight','Qty','Thk','Total Price'};
[r,c] = find(contains(A,'Price'))

1 件のコメント

abb Shp
abb Shp 2020 年 11 月 17 日
thanks Stephan, works well, I appreciate

サインインしてコメントする。

その他の回答 (2 件)

Ameer Hamza
Ameer Hamza 2020 年 11 月 16 日

1 投票

Another solution using regexpi() which takes care of the letter-case too.
[r, c] = find(~cellfun(@isempty, regexpi(A, 'price')))

3 件のコメント

abb Shp
abb Shp 2020 年 11 月 17 日
Thanks Ameer, this works too, but letter-case is not important to me in this case, thnx anyway.
Ameer Hamza
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.
abb Shp
abb Shp 2020 年 11 月 17 日
Thanks :)

サインインしてコメントする。

Setsuna Yuuki.
Setsuna Yuuki. 2020 年 11 月 16 日

0 投票

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)

1 件のコメント

abb Shp
abb Shp 2020 年 11 月 17 日
thnx Bastian, this works too but wants a more general code

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

質問済み:

2020 年 11 月 16 日

コメント済み:

2020 年 11 月 17 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by