how to convert cell array to a matrix?

2 次查看(过去 30 天)
I have a 5X4 matrix whose each element is a cell array. how to convert it to a simple matrix of elements.
  5 个评论
Zara Khan
Zara Khan 2018-7-30
I want to access this matrix as row by row
Zara Khan
Zara Khan 2018-7-31
Bhowmik U: No its not working as we cant use cell for cell arrays.

请先登录,再进行评论。

回答(1 个)

Jos (10584)
Jos (10584) 2018-7-30
A = {[1 2 3],[4 5],6 ; [11 12],13,[] ; 21, [22 23], [24 25]} % data
B = arrayfun(@(k) cat(2,A{k,:}),1:size(A,1),'un',0) % make row vectors
C = padcat(B{:}) % pad vectors with NaNs
  6 个评论
Zara Khan
Zara Khan 2018-7-31
yes that can be done using the above code. But what about when I am storing values from loops?
Jos (10584)
Jos (10584) 2018-8-1
This is all rather vague ... Can you show us some code, showing where you get stuck?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by