Two cell arrays indexing
4 views (last 30 days)
Show older comments
I have two cell Arays, lets say
A = {[],[],[2,3],[1,2]}
B = {[1,2,3],[4,5],[6,7,8],[9,10,11]}
"A" contains the Index of the numbers I am trying to get out of "B". So the [2,3] from A corresponds to the numbers [7,8] from B.
Now I would like my output to be:
output = {[],[],[7,8],[9,10]}
My original data is much larger than this, so ideally a general solution would be great.
Any help is greatly appreciated.
0 Comments
Accepted Answer
dpb
on 10 Nov 2020
Edited: dpb
on 10 Nov 2020
C=cellfun(@(a,b)b(a),A,B,'UniformOutput',false);
It's just logical indexing in a background loop under the guise of cell addressing. Seems more complicated than actually is.
>> C=cellfun(@(a,b)b(a),A,B,'UniformOutput',false);
>> C{:}
ans =
[]
ans =
[]
ans =
7 8
ans =
9 10
>>
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!