ismember structure?

4 visualizaciones (últimos 30 días)
Trader
Trader el 3 de Abr. de 2012
I have a structure that consists of cell arrays that contain both doubles and strings.
results =
full_data: {401x17 cell}
order_data: {11x17 cell}
I'd like to create an array that is the size of full_data but only has the dates that are in order_data. How do you do this?
Thanks for your help!
  1 comentario
Sean de Wolski
Sean de Wolski el 3 de Abr. de 2012
Are all 11*17 values in order_data dates?

Iniciar sesión para comentar.

Respuestas (1)

owr
owr el 3 de Abr. de 2012
I like to use "intersect" for this, though "ismember" could do the trick similarly. I like intersect because I dont have to assume that the dates in order_data are a subset of full_data.
Lets say your dates look like this:
>> dates_full = (734953:734962)'
dates_full =
734953
734954
734955
734956
734957
734958
734959
734960
734961
734962
>> dates_order = [734954; 734958]
dates_order =
734954
734958
Create a new array to hold your results:
>> results_full = nan(size(dates_full))
results_full =
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
Fill the rows in results_full with the dates from dates_order that correspond to matching dates between dates_full and dates_order:
>> [temp,indx_full,indx_order] = intersect(dates_full,dates_order)
temp =
734954
734958
indx_full =
2
6
indx_order =
1
2
>> results_full(indx_full) = dates_order(indx_order)
results_full =
NaN
734954
NaN
NaN
NaN
734958
NaN
NaN
NaN
NaN

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by