필터 지우기
필터 지우기

How to get the row indices

조회 수: 3 (최근 30일)
Kanakaiah Jakkula
Kanakaiah Jakkula 2017년 4월 13일
댓글: Walter Roberson 2017년 4월 14일
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
Steven Lord
Steven Lord 2017년 4월 13일
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 2017년 4월 13일
cell array

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

채택된 답변

Walter Roberson
Walter Roberson 2017년 4월 13일
편집: Walter Roberson 2017년 4월 13일
S = { 'PRS.BG02K65E5T9',
'PRS.UG02K145E5T20',
'Ark.prgrma',
'YUI_PRS.UG02K145E5T20',
'PRS.GG02K200E6T20'};
find(strncmp(S,'PRS',3))
  댓글 수: 2
Kanakaiah Jakkula
Kanakaiah Jakkula 2017년 4월 13일
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 2017년 4월 14일
mask = strncmp(S,'PRS',3);
row_indices = find(mask);
match_count = sum(mask);
nonmatch_count = sum(~mask);

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by