Extract only some specific elements of the arrays of a cell
9 ビュー (過去 30 日間)
古いコメントを表示
I have a cell, say C, where each array is also a cell. I have an index set and I want to extract cells 2, 5,1. It can be done by using . But it returns a cell where each cell is still a cell. What I want to know is how I can extract a new cell that contains cells 2,5, and 1 of the original cell, and also for each individual cell, it only contains cells 2,5, and 1. Therefore, the final cell is a cell and all individual cells are also a cell.
0 件のコメント
採用された回答
Stephen23
2022 年 4 月 5 日
C = arrayfun(@(n)num2cell(rand(1,5)),1:5,'uni',0)
C{:}
X = [2,5,1];
D = cellfun(@(d)d(X),C(X),'uni',0)
D{:}
その他の回答 (1 件)
KSSV
2022 年 4 月 5 日
C = cell(5,1) ;
for i = 1:5
C{i} = rand(1,3) ;
end
idx = [2 5 1] ;
iwant = C(idx)
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!