using strcmp for index

조회 수: 7 (최근 30일)
John Millerhagen
John Millerhagen 2019년 2월 15일
답변: Star Strider 2019년 2월 15일
I have a data file that must be in a specific order through a descending column. I want to check that the data in my cells is in the correct order.
my file should have the following order within the 4th column:
'BLCU'
'BLCD'
'BLCU'
'BLCD'
'BLCU'
%etc etc. also, I have another file that has the following order in (again, the 4th column)%
'OGCU'
'OGSS'
'OGES'
'OGSA'
'OGLO'
'OGCD'
%trials is the name of my array
%was thinking of something along the lines of underneath (this obviously does not work)
for x = 1:100
strcmp(trials{x:x+1,4},'BLCU' 'BLCD')
disp(trials{x,3})
end
%ie making sure that each "chunk" of code is in the correct order before proceeding to the following chunk
My chunks have to be in the correct order and they have to follow one another, but obviously strcmp() cannot compare two cells at once. I would like to return the index (located in cell 3) where the error occurs if a chunk is incorrect. Finally, I also need to detect typos (ie. a OGES labeled as a OGED, etc).
Thanks in advance

답변 (1개)

Star Strider
Star Strider 2019년 2월 15일
Try this:
pos{x} = strcmp(trials{x},{'BLCU' 'BLCD'});

카테고리

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