Find exact vector order in another vector array
I am trying to find a way to grab indivdual cells within a cell array that I can then use to find the exact order found in a larger matrix array.
I am having a difficult time trying to find a way to grab the exact order/vector in each cell array to locate the indices in the second larger matrix array.
For example, my cell array "att_event_codes" is the array I’m grabbing my desired vectors to find in the larger matrix array:
att_event_codes{1,1} : 9 10 12 11 20 12 33 21 42 22 18
att_event_codes{1,2}: 9 10 12 11 20 12 33 21 40 41 22 18
If I grab, for example, att_event_codes{1,1} as a vector I want to use:
vector = (att_event_codes{1,1});
I want to take that vector assignment to find the exact order of event codes in my larger matrix called "event_codes" (1×19277 double).
I have tried several matlab functions such as find, ismember, and strcmp and have been unable to figure out how to get them to work taking into account the entire vector rather than working with individual items within the vector. For example:
vector = (att_event_codes{1,1});
mask = ismember(event_codes,vector);
test = find(mask)
test returns 1×14953 double
Another way that I’ve tried (which is probably a better way to do this):
[~,test] = ismember(vector, event_codes)
test returns 1×11 double:
1 2 3 8 4 3 25 11 3655 5 15
The correct (desired) answser for this "test" would return an index of 3647:3657.
Thank you.I am trying to find a way to grab indivdual cells within a cell array that I can then use to find the exact order found in a larger matrix array.
I am having a difficult time trying to find a way to grab the exact order/vector in each cell array to locate the indices in the second larger matrix array.
For example, my cell array "att_event_codes" is the array I’m grabbing my desired vectors to find in the larger matrix array:
att_event_codes{1,1} : 9 10 12 11 20 12 33 21 42 22 18
att_event_codes{1,2}: 9 10 12 11 20 12 33 21 40 41 22 18
If I grab, for example, att_event_codes{1,1} as a vector I want to use:
vector = (att_event_codes{1,1});
I want to take that vector assignment to find the exact order of event codes in my larger matrix called "event_codes" (1×19277 double).
I have tried several matlab functions such as find, ismember, and strcmp and have been unable to figure out how to get them to work taking into account the entire vector rather than working with individual items within the vector. For example:
vector = (att_event_codes{1,1});
mask = ismember(event_codes,vector);
test = find(mask)
test returns 1×14953 double
Another way that I’ve tried (which is probably a better way to do this):
[~,test] = ismember(vector, event_codes)
test returns 1×11 double:
1 2 3 8 4 3 25 11 3655 5 15
The correct (desired) answser for this "test" would return an index of 3647:3657.
Thank you. I am trying to find a way to grab indivdual cells within a cell array that I can then use to find the exact order found in a larger matrix array.
I am having a difficult time trying to find a way to grab the exact order/vector in each cell array to locate the indices in the second larger matrix array.
For example, my cell array "att_event_codes" is the array I’m grabbing my desired vectors to find in the larger matrix array:
att_event_codes{1,1} : 9 10 12 11 20 12 33 21 42 22 18
att_event_codes{1,2}: 9 10 12 11 20 12 33 21 40 41 22 18
If I grab, for example, att_event_codes{1,1} as a vector I want to use:
vector = (att_event_codes{1,1});
I want to take that vector assignment to find the exact order of event codes in my larger matrix called "event_codes" (1×19277 double).
I have tried several matlab functions such as find, ismember, and strcmp and have been unable to figure out how to get them to work taking into account the entire vector rather than working with individual items within the vector. For example:
vector = (att_event_codes{1,1});
mask = ismember(event_codes,vector);
test = find(mask)
test returns 1×14953 double
Another way that I’ve tried (which is probably a better way to do this):
[~,test] = ismember(vector, event_codes)
test returns 1×11 double:
1 2 3 8 4 3 25 11 3655 5 15
The correct (desired) answser for this "test" would return an index of 3647:3657.
Thank you. vector indexing, indexing, vectors MATLAB Answers — New Questions