Pattern search and string indexing
이전 댓글 표시
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개)
madhan ravi
2020년 6월 4일
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
Ronald
2020년 6월 4일
Ameer Hamza
2020년 6월 5일
FYI, following code will slice A as you want
C = A([B{:}])
카테고리
도움말 센터 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!