How to convert a 3x3xN matrix to a N element cell array?

조회 수: 2 (최근 30일)
Alon Rozen
Alon Rozen 2016년 11월 21일
댓글: Alexandra Harkai 2016년 11월 21일
Hi all,
I have a three dimension matrix of 3x3xN, where N is a large number. I want to convert it to a N elements cell array in which every cell i contains the 3x3 matrix in the i'th position. I tried to work it out using the functions 'mat2cell' and 'num2cell' but couldn't understand how to do it. I read the help for these two functions but it didn't help me.
Can it be done?
Thanks,
Alon

채택된 답변

Alexandra Harkai
Alexandra Harkai 2016년 11월 21일
편집: Alexandra Harkai 2016년 11월 21일
% a is your 3*3*N array
c = mat2cell(a,3,3,ones(1,N));
c = c(:);
  댓글 수: 2
Alon Rozen
Alon Rozen 2016년 11월 21일
Thanks a lot! works like charm :) Wander why the help can't explain something like this...
Alexandra Harkai
Alexandra Harkai 2016년 11월 21일
It does actually (ie. you first want something that contains 3*3*1 elements in each cell, so according to help you need to go for [3],[3],[1 1 ...]), but that doesn't mean one doesn't get it wrong for the first try. Trial an error :)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

KSSV
KSSV 2016년 11월 21일
A = rand(3,3,100) ;
[m,n,t] = size(A) ;
iwant=mat2cell(A, m, n, ones(1,t));
  댓글 수: 1
Alon Rozen
Alon Rozen 2016년 11월 21일
Thanks a lot! It work of cousre. I just needed the last step in the answer above.

댓글을 달려면 로그인하십시오.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by