Cell to matrix conversion of different dimension

2 ビュー (過去 30 日間)
sam moor
sam moor 2017 年 1 月 18 日
編集済み: Angela Caliwag 2021 年 10 月 22 日
I have a 1x44 cell with different dimension. I want to change those cell in to single matrix so that I can do manipulation? I try cell2mat but no luck. Is there any way to change cell to matrix of different dimension?
  3 件のコメント
sam moor
sam moor 2017 年 1 月 18 日
Yes, each cell in the cell array is with different dimension. when i try cell2mat it says "Dimensions of matrices being concatenated are not consistent"
sam moor
sam moor 2017 年 1 月 18 日
This is the cell array I have. I want to change this cell to matrix but it has different dimensions.

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

採用された回答

Walter Roberson
Walter Roberson 2017 年 1 月 18 日
"Is there any way to change cell to matrix of different dimension?"
Not to a numeric matrix, No. Numeric matrices require consistent dimensions.
You could potentially pad the various parts out with NaN or inf or 0 as required so that the parts were the same shape. That gets a bit complex if the arrays might be different numbers of dimensions.
  4 件のコメント
Walter Roberson
Walter Roberson 2017 年 1 月 19 日
ColFirstN = @(V, L) V(1:L);
ColPad = @(V, L) ColFirstN( [V; zeros(L, 1)], L);
maxlen = 18000;
padded_gm = cellfun(@(V) ColPad(V, maxlen), gm), 'Uniform', 0);
gm_matrix = cell2mat(padded_gm);
Angela Caliwag
Angela Caliwag 2021 年 10 月 22 日
編集済み: Angela Caliwag 2021 年 10 月 22 日
@sam moor How did you resolve this please?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by