How can I index using cell arrays?

조회 수: 7 (최근 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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by