필터 지우기
필터 지우기

Find the cell which is containing a string

조회 수: 1 (최근 30일)
abb Shp
abb Shp 2020년 11월 16일
댓글: abb Shp 2020년 11월 17일
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일
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일
Another solution using regexpi() which takes care of the letter-case too.
[r, c] = find(~cellfun(@isempty, regexpi(A, 'price')))
  댓글 수: 3
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일
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

댓글을 달려면 로그인하십시오.

카테고리

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