how to convert cell array to a matrix?
이전 댓글 표시
I have a 5X4 matrix whose each element is a cell array. how to convert it to a simple matrix of elements.
댓글 수: 5
Bhowmik.U
2018년 7월 30일
try if this works
X=cell{5,4} %your cell Y=cell2mat(X) % your desired matrix
Stephen23
2018년 7월 30일
@Zara Khan: what size would you expect the output to be? Would padding be acceptable to you? If so, with what value?
KSSV
2018년 7월 30일
Attach data instead of image snippet..have a look on Cell2mat
Zara Khan
2018년 7월 30일
Zara Khan
2018년 7월 31일
답변 (1개)
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
My function PADCAT can be downloaded here: https://uk.mathworks.com/matlabcentral/fileexchange/22909-padcat-varargin
댓글 수: 6
Jos (10584)
2018년 7월 31일
use d instead of A to create B ... I am no sure if I understand your problem though ...
Zara Khan
2018년 7월 31일
Jos (10584)
2018년 7월 31일
At some point you will have a cell array with values, won't you? Then you can transform it as above.
Zara Khan
2018년 7월 31일
Jos (10584)
2018년 8월 1일
This is all rather vague ... Can you show us some code, showing where you get stuck?
카테고리
도움말 센터 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!