Find row where cell value equals some defined value

Hi,
I have a list called quarters that looks something like:
1999Q2
1999Q3
1999Q4
2000Q1
I would like to find out which row is for example 1999Q4. So I have defined:
quarter_find='1999Q4'
How could I find the right row? I tried with find function: [row_equal]=strfind(quarters, quarter_find)
I get
[]
[]
1
[]
How could I actually get number of row where those values are equal? (so in this case I would like to ger answer=3)
Could anyone please suggest me something?
Thanks,
Ieva

 Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 23 Mär. 2012
eg
data = {'1999Q2'
'1999Q3'
'1999Q4'
'2000Q1'}
out = find(~cellfun('isempty',strfind(data,'Q4')))

3 Kommentare

Ieva
Ieva am 23 Mär. 2012
Great thank you! It works perfectly! :)
Venkat Ta
Venkat Ta am 18 Mär. 2017
Bearbeitet: Venkat Ta am 18 Mär. 2017
suppose, the data are '10' '10.66' '11' '20' like this, I would like to find out only 10 not 10.66 exactly 1st row only not both the 1 and 2?
And my data is like 90x1 double?
Jan
Jan am 21 Mär. 2017
@Venkatesan Thanigaiarasu: Please do not highjack an existing thread. Open a new thread for a new question. Thanks.
'10' '10.66' '11' '20' does not look like a "90 x 1 double". Please clarify this (in the new thread of course).

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Jan
Jan am 23 Mär. 2012

0 Stimmen

The command posted by Andrei is the best Matlab solution I know, but it does not look nice, althozugh this is a standard problem. Therefore I'm using FEX: strncmpr. This function is equivalent to strncmp, but processes the strings from the right. E.g. this helps to filter file names by their extensions.

Kategorien

Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 23 Mär. 2012

Kommentiert:

Jan
am 21 Mär. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by