Finding a column with specific text
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
BENJAMIN BUCHDA
le 15 Fév 2021
Commenté : Star Strider
le 15 Fév 2021
I am trying to create a function that takes a array of characters and finds the first column that has a specific input. It seems to work however when I ask have cells with multiple characters an error message saying matrix dimensions must agree. Not sure what I am doing wrong. Any suggestions?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/520332/image.png)
0 commentaires
Réponse acceptée
Star Strider
le 15 Fév 2021
3 commentaires
Adam Danz
le 15 Fév 2021
Modifié(e) : Adam Danz
le 15 Fév 2021
strcmp/strcmpi returns the index number.
If your array is 1D (vector) then you're problem is solved.
If your array is >1D you can use ind2sub to get the column number.
ind = strcmpi(YourArray, subStr);
[~, col] = ind2sub(size(YourArray),find(ind));
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements 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!