Pulling matrix column data out of a cell

2 ビュー (過去 30 日間)
Zach Wallace
Zach Wallace 2016 年 11 月 12 日
コメント済み: James Tursa 2016 年 11 月 12 日
I have a cell array with 29 matrices that are each 500x6 doubles. I want to take the first column of each matrix and load them into a single matrix that is 500x29. Then, I want to do this with each column, ending with 6 matrices of 500x29. I feel like theres a way to do this with a for loop I just dont know how. Help?

採用された回答

Ahmet Cecen
Ahmet Cecen 2016 年 11 月 12 日
Say your Cell array is C:
D = cell2mat(C);
E = reshape(D(:),[500 29*6]);
Now every 500 by 29 chunk in E is a matrix you want.
  2 件のコメント
Zach Wallace
Zach Wallace 2016 年 11 月 12 日
I didnt know about cell2mat, thanks! But I'm not sure why you need reshape?
James Tursa
James Tursa 2016 年 11 月 12 日
Slight edit:
D = cell2mat(C(:)); % Use C(:) to ensure columns line up
E = reshape(D,[500 29 6]); % So 3rd index picks off the 500x29 matrix
I.e., E(:,:,1) is your 1st matrix, E(:,:,2) is your 2nd matrix, etc. Could of course use mat2cell on E if you wanted the result in a cell array.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by