Cell to matrix conversion of different dimension
2 次查看(过去 30 天)
显示 更早的评论
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?
采纳的回答
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
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);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!