Effacer les filtres
Effacer les filtres

Find the cell which is containing a string

1 vue (au cours des 30 derniers jours)
abb Shp
abb Shp le 16 Nov 2020
Commenté : abb Shp le 17 Nov 2020
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

Réponse acceptée

Stephan
Stephan le 16 Nov 2020
A={'Dimension','Weight','Qty','Thk','Total Price'};
[r,c] = find(contains(A,'Price'))
  1 commentaire
abb Shp
abb Shp le 17 Nov 2020
thanks Stephan, works well, I appreciate

Connectez-vous pour commenter.

Plus de réponses (2)

Ameer Hamza
Ameer Hamza le 16 Nov 2020
Another solution using regexpi() which takes care of the letter-case too.
[r, c] = find(~cellfun(@isempty, regexpi(A, 'price')))
  3 commentaires
Ameer Hamza
Ameer Hamza le 17 Nov 2020
Modifié(e) : Ameer Hamza le 17 Nov 2020
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 le 17 Nov 2020
Thanks :)

Connectez-vous pour commenter.


Setsuna Yuuki.
Setsuna Yuuki. le 16 Nov 2020
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 commentaire
abb Shp
abb Shp le 17 Nov 2020
thnx Bastian, this works too but wants a more general code

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by