필터 지우기
필터 지우기

How I can combine this cell values in a single matrix?

조회 수: 2 (최근 30일)
Sourasis Chattopadhyay
Sourasis Chattopadhyay 2021년 8월 16일
댓글: Simon Chan 2021년 8월 17일
I want to get my output  in (12X28) matrix
How I can get in a single (12X28) matrix
  댓글 수: 2
Simon Chan
Simon Chan 2021년 8월 16일
If the size of the first cell is [5x7 double], you may combine them to become a (12x7) matrix because all of them have 7 columns only.
Or you would like to repeat the cells until the final one has 28 columns?
Sourasis Chattopadhyay
Sourasis Chattopadhyay 2021년 8월 17일
First cell is [1X7 double].
I am looking for (12X28) = Row(1*3*2*2) and Column (7+7+7+7).
as example,

댓글을 달려면 로그인하십시오.

답변 (2개)

Wan Ji
Wan Ji 2021년 8월 16일
If X{1} is 1x7 array, the simplest way is
matrixOut = cell2mat(X')
  댓글 수: 6
Wan Ji
Wan Ji 2021년 8월 17일
If your rowNum is a variable, is it calculated in this way?
RowNum = prod(arrayfun(@(i)size(X{i},1), 1:1:numel(X)))
Then
RowNum =
12
The whole code my be
RowNum = prod(arrayfun(@(i)size(X{i},1), 1:1:numel(X)));
X = arrayfun(@(i)repmat(X{i},RowNum/size(X{i},1),1), 1:1:numel(X), 'uniform', 0);
A = cell2mat(X) % A is what you want

댓글을 달려면 로그인하십시오.


Simon Chan
Simon Chan 2021년 8월 17일
편집: Simon Chan 2021년 8월 17일
Something like this and final matrix is C
clear; clc;
X = cell(1,4);
X{1} = round(10*rand(1,7));
X{2} = round(10*rand(3,7));
X{3} = round(10*rand(2,7));
X{4} = round(10*rand(2,7));
B{1} = repmat(X{1},12,1);
B{2} = repmat(kron(X{2},ones(2,1)),2,1);
B{3} = repmat(X{3},6,1);
B{4} = kron(X{4},ones(6,1));
C = cell2mat(B);
  댓글 수: 2
Sourasis Chattopadhyay
Sourasis Chattopadhyay 2021년 8월 17일
If my cell size is cange in this case It is not possiable to do by manually . In case my cell size is (mXn) ,then what should I do?
Simon Chan
Simon Chan 2021년 8월 17일
Need to know the pattern how to repeat the matrix. If a pattern can be found, it is able to implement it in a loop.
However, I am also confused since the repeating method of a 2 rows matrix may be different (The left and right matrix in your elaboration).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by