MATLAB Answers

Cell Array Transform to Matrix as same sizes?

1 view (last 30 days)
delil codes
delil codes on 20 Apr 2021
Commented: delil codes on 20 Apr 2021
I have a cell array like;
How can i transform it like matrix as same sizes?
There is any function for this?
  2 Comments
delil codes
delil codes on 20 Apr 2021
eg: 2x3 cell;
6x6 sym 6x18 sym 6x12 sym
6x6 sym 6x18 sym 6x12 sym
to
12x36 matrix
i did it :)
lineStart = 1;
[lines,columns] = size(rectangularCell);
for i = 1:lines
columnStart =1;
for j = 1:columns
[xSizes, ySizes] = size(rectangularCell{i,j});
rectangularMatrix...
(lineStart:lineStart+xSizes-1,columnStart:columnStart+ySizes-1) ...
= rectangularCell{i,j};
columnStart = columnStart + ySizes;
end
lineStart = lineStart + xSizes;
end

Sign in to comment.

Answers (2)

VBBV
VBBV on 20 Apr 2021
Use cell2mat function
  3 Comments

Sign in to comment.


delil codes
delil codes on 20 Apr 2021
Thx guys i did it, you can use this for rectangular cells to rectangular matrix. If your cell have cells lıke;
eg: 2x3 cell;
6x6 sym 6x18 sym 6x12 sym
6x6 sym 6x18 sym 6x12 sym
to
12x36 matrix
lineStart = 1;
[lines,columns] = size(rectangularCell);
for i = 1:lines
columnStart =1;
for j = 1:columns
[xSizes, ySizes] = size(rectangularCell{i,j});
rectangularMatrix...
(lineStart:lineStart+xSizes-1,columnStart:columnStart+ySizes-1) ...
= rectangularCell{i,j};
columnStart = columnStart + ySizes;
end
lineStart = lineStart + xSizes;
end

Community Treasure Hunt

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

Start Hunting!

Translated by