Pattern search and string indexing
Show older comments
I have two cell arrays:
A = {[x(2)& x(4)& x(1)],[x(3),x(5)],[x(2),x(1)]}
B = {2465,2514,147,236,58}
where the integers in A are the indices of B items. I want to replace those indices with actual values as:
C = {[2514,236,2465],[147,58],[2514,2465]}
For loop is a bit slow. Is there an alternative?
1 Comment
madhan ravi
on 4 Jun 2020
Why would you do that?
Accepted Answer
More Answers (1)
madhan ravi
on 4 Jun 2020
A = @(x){[x(2), x(4), x(1)],[x(3),x(5)],[x(2),x(1)]}
B = {2465,2514,147,236,58}
C = A(B)
2 Comments
Ronald
on 4 Jun 2020
Ameer Hamza
on 5 Jun 2020
FYI, following code will slice A as you want
C = A([B{:}])
Categories
Find more on Matrices and Arrays 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!