MATLAB: Comparing to string vectors

comparedatefindintersectismemberposition;strings

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

Best Answer

hey
The way you are defining your arrays causes them to be stored as type int. For example:
date = [12-10-1992;13-10-1992]; -----> date = [-1990,-1989]
date2 = [13-10-1992;14-10-1992]; -----> date2 = [-1989,-1988]
I suppose in this case, you would get lucky because comparing same "dates" would be comparing the integer values, which would turn out to be the same. However, if you actually want to comparing strings, you should define them like this:
date = ['12-10-1992','13-10-1992'];
date2 = ['13-10-1992','14-10-1992'];
Then
find(date == date2)
will return the indices at which the string values are the same