ismember structure?

7 次查看(过去 30 天)
Trader
Trader 2012-4-3
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 个)

owr
owr 2012-4-3
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

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by