ismember structure?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Risposte (1)
owr
il 3 Apr 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
0 Commenti
Vedere anche
Categorie
Scopri di più su Structures in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!