1X1500 cell array to matrix

조회 수: 2 (최근 30일)
Arup Bhattacharya
Arup Bhattacharya 2019년 1월 24일
댓글: Adam Danz 2019년 1월 25일
I have 1500 .txt files containing 5 columns and 71022 rows. I converted them into 1x1500 cell array using import tool. Now the new table data has 1500 tables, each having 5 columns and 71022 rows. I want to have a 3-D matrix. How do I do that?

답변 (2개)

Adam Danz
Adam Danz 2019년 1월 24일
Since each matrix is the same size, here's an easy solution: If your cell array is named 'ca', 'm' will be your 3D array.
m = reshape(cell2mat(ca), 71022, 5, 1500);
How this works:
cell2mat() converts your 1x1500 cell into a 71022x(1500*5) matrix.
reshape() converts that matrix into a 3D array with 71022 rows, 5 columns, and 1500 pages.
  댓글 수: 12
Image Analyst
Image Analyst 2019년 1월 25일
Maybe there is a better way, like csvread(), importdata(), readtable(), textscan(), etc. where you don't have to mess with the complication of cell arrays.
Someone could probably tell you if you attach your text file.
Adam Danz
Adam Danz 2019년 1월 25일
My solution works when your variable is a cell array and each element of the cell array is a matrix. I'll need to look at your variable to help further. You could save your variable to a mat file and upload it here.

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


Bob Thompson
Bob Thompson 2019년 1월 24일
You can try using cell2mat(), but I'm not intimately familiar with it enough to know if it will work with arrays inside each cell, or if you need to just have doubles.
Alternatively, you can always just use a loop:
for i = 1:size(cellarray,2)
3dmatrix(:,:,i) = cellarray{i};
end

카테고리

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

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by