How can I index using cell arrays?

12 ビュー (過去 30 日間)
Dominik Mattioli
Dominik Mattioli 2017 年 2 月 8 日
回答済み: Guillaume 2017 年 2 月 8 日
A = randi(100,1,8); % Some array that I want to index into.
B = {[1;2;3];[4;5];[6];[7;8]}; % Cell array with indices.
%I want to index B into A to get:
C = {[A(1);A(2);A(3)];...;[A(7);A(8)]}

採用された回答

Guillaume
Guillaume 2017 年 2 月 8 日
cellfun(@(b) A(b), B, 'UniformOutput', false)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by