how to duplicate the values in one matrix create another matrix of specific dimension

조회 수: 2 (최근 30일)
i have a cell array of dimension 1x60, each matrix in cell array is of dimension 23x23 of double datatype
i converted this cell array to matrix using cell2mat and got a matrix A, of dimension 23x1380
how can i duplicate the values in the matrix A, to create another matrix B, of dimension 368x19872 double datatype using any suitable pattern
The values can be duplicated in any suitable pattern to achieve a matrix of dimension 368x19872 (either from [1 2 3] to [1 1 1 2 2 2 3 3 3] or to [1 2 3 1 2 3 1 2 3])
is it possible to get a matrix of dimension 368x19872, from the cell array 1x60 directly without converting to matrix of dimension 23x1380 ?
any suitable replicating method can be choosen. only the output dimension with the same data values is needed

채택된 답변

ME
ME 2019년 11월 1일
Assuming you want the rest of the larger matrix to be zeros, then you could use:
s=size(A);
B(1:s(1),1:s(2)) = A;
This will set A as the first 23x1380 elements of B. Is that what you wanted?
  댓글 수: 3
ME
ME 2019년 11월 1일
The column dimension won't come out correctly using that approach because your desired dimension is not an integer multiple of the original matrix.
Probably the easiest way is to use repmat to make a larger than desired matrix and then trim it down afterwards with something like:
Des = [368 19872];
s=size(A);
B=repmat(A,ceil(Des(1)/s(1)),ceil(Des(2)/s(2)));
B = B(1:Des(1),1:Des(2));
Guillaume
Guillaume 2019년 11월 1일
@Elysi, You've asked enough questions here over the years that by now you should know how to write a question properly, i.e. give as many details as possible about what you want. How should the values be duplicated (do we go from [1 2 3] to [1 1 1 2 2 2 3 3 3] or to [1 2 3 1 2 3 1 2 3])? Why is 19872 not a multiple of 1380 and therefore how do you duplicate something by a fraction?
If you don't give details, people have to guess at what you want and may get it wrong, wasting your and their time.

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

추가 답변 (0개)

카테고리

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