필터 지우기
필터 지우기

How can I extract all matrix elements for one index with dynamic number of dimenstions?

조회 수: 1 (최근 30일)
Hello experts,
let A be
A = rand(4, 4, 4); %
so what I want is:
B = reshape(A(1,:,:), [4 4])
The problem is the unknown dimension of A. So if A has the dimension of 3, I need 2 colon operator; if 4 then 3 and so on...
I am very thankful for any ideas...
BR

채택된 답변

Andrei Bobrov
Andrei Bobrov 2017년 4월 6일
ii = repmat({':'},1,ndims(A)-1);
out = squeeze(A(1,ii{:}));

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by