How to get the row indices

3 vues (au cours des 30 derniers jours)
Kanakaiah Jakkula
Kanakaiah Jakkula le 13 Avr 2017
Commenté : Walter Roberson le 14 Avr 2017
Hi,
I have the below array, and I want to get the idices of names starting with PRS.
PRS.BG02K65E5T9
PRS.UG02K145E5T20
Ark.prgrma
YUI_PRS.UG02K145E5T20
PRS.GG02K200E6T20
1. I want to know which row of name start with PRS. (row1,2,5) 2. Count of names starting with PRS. and not start with PRS. (3 &2)
Many thanks in advance,
  2 commentaires
Steven Lord
Steven Lord le 13 Avr 2017
How is the data stored? As a char array, as a cell array each element of which is a char vector, as a string array, etc.? And which release of MATLAB are you using?
Kanakaiah Jakkula
Kanakaiah Jakkula le 13 Avr 2017
cell array

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 13 Avr 2017
Modifié(e) : Walter Roberson le 13 Avr 2017
S = { 'PRS.BG02K65E5T9',
'PRS.UG02K145E5T20',
'Ark.prgrma',
'YUI_PRS.UG02K145E5T20',
'PRS.GG02K200E6T20'};
find(strncmp(S,'PRS',3))
  2 commentaires
Kanakaiah Jakkula
Kanakaiah Jakkula le 13 Avr 2017
I also want to know the count of of names starting with PRS and not starting with PRS: my output should be [3 2]
Walter Roberson
Walter Roberson le 14 Avr 2017
mask = strncmp(S,'PRS',3);
row_indices = find(mask);
match_count = sum(mask);
nonmatch_count = sum(~mask);

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by