change the dimension of a cell in a cell array

조회 수: 4 (최근 30일)
ZEMIN HUANG
ZEMIN HUANG 2021년 1월 26일
댓글: Image Analyst 2021년 1월 31일
hi, i have a cell array of size 480000x1, in each cell, the size is 384x1 as shown in the picture. I would like to change the 384x1 dimension of every cell to 6x64. could anyone help me please? thanks in advance.
i tried writing the below code but got an error. help please!

채택된 답변

David Hill
David Hill 2021년 1월 26일
for k=1:length(XTrain)
XTrain{k}=reshape(XTrain{k},6,[]);
end

추가 답변 (1개)

Image Analyst
Image Analyst 2021년 1월 26일
You almost definitely should not use a cell array for this. They are slow and have lots of overhead. It looks like you can use a regular double 480000 x 384 matrix, or even a table. Just start out with a 3-D array of 480000 x 6 x 64.
  댓글 수: 3
ZEMIN HUANG
ZEMIN HUANG 2021년 1월 31일
hi image analyst, how do i convert the cell array to 480000x384 matrix that you mentioned
Image Analyst
Image Analyst 2021년 1월 31일
You would not convert it because you would/should never create a cell array in the first place. You would just do
for row = 1 : 48000
for k = 1 : 64
column1 = (k-1) * 6 + 1;
column2 = column1 + 5;
m(row, column1 : column2) = someVectorOfLength6;
end
end

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by