Comparing to string vectors
Ältere Kommentare anzeigen
Hi guys,
I am having a lot of trouble comparing 2 arrays of strings.
For example, I have:
date = ['12-10-1992';'13-10-1992';'14-10-1992';'15-10-1992'];
date2=['13-10-1992';'14-10-1992'];
I want to compare them and find the position for which date 2 is equal to date.
I tried using find, ismember, intersect..none of them are working and i don´t understand why..
can anyone help please?
I would be much appreciated!
Inês
2 Kommentare
James Tursa
am 8 Jul. 2015
Please verify first what class of variables you have. What is class(date) and class(date2)?
Inês Mendes
am 8 Jul. 2015
Akzeptierte Antwort
Weitere Antworten (1)
James Tursa
am 8 Jul. 2015
The intersect function works for me, as long as I start with cell arrays as you have stated. E.g.,
>> date1 = {'12-10-1992';'13-10-1992';'14-10-1992';'15-10-1992'};
>> date2 = {'13-10-1992';'14-10-1992'};
>> [d i1 i2] = intersect(date1,date2)
d =
'13-10-1992'
'14-10-1992'
i1 =
2
3
i2 =
1
2
Can you verify again that you really have cell arrays?
2 Kommentare
Inês Mendes
am 8 Jul. 2015
James Tursa
am 8 Jul. 2015
Examine those exact mismatches in detail. Are they in exactly the same format? Do either of them have leading or trailing blanks? Etc. Once you know the cause of the mismatch and the formats you are working with, you can design code to deal with it.
Kategorien
Mehr zu Time Series Objects finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!