How to repeat elements of a matrix

조회 수: 3 (최근 30일)
charu shree
charu shree 2023년 4월 4일
댓글: Jon 2023년 4월 4일
Hello all, I am having a matrix of size 8 by 16.
My query is how to obtain 8 by 500 matrix from 8 by 16 matrix.
Any help is highly appreciated.
  댓글 수: 3
charu shree
charu shree 2023년 4월 4일
Thank u sir for ur answer.
Basically I am having 16 column vectors each of size 8 by 1. I had arranged them to obtain another matrix of size 8 by 16. Now I want to make 8 by 500 matrix.
I understand that we can get 8 by 496 matrix. But is it possible to append any 4 colums of earlier 8 by 16 matrix to this new 8 by 496 matrix so that it forms 8 by 500 matrix ?
Steven Lord
Steven Lord 2023년 4월 4일
Why not just pad your 8-by-16 array with 500-16 columns of NaN values?
x = reshape(1:8*16, [8 16]);
x(:, 17:500) = NaN;
Or fill in with random values:
x = reshape(1:8*16, [8 16]);
x(:, 17:500) = rand(8, 500-16);
What are the specific requirements for how you want the additional columns to be created?

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

채택된 답변

Jon
Jon 2023년 4월 4일
편집: Jon 2023년 4월 4일
So is this what you want?
A = rand(8,16);
B = [repmat(A,1,31) A(:,1:4)];
In this case the last 4 columns of the 8 by 500 are the first 4 columns of the original 8 by 16 but you could use other columns if you wanted, just put in the indices you want
  댓글 수: 2
charu shree
charu shree 2023년 4월 4일
@Jon, once again thank u sir for ur detailed solution....
Jon
Jon 2023년 4월 4일
You're welcome

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

추가 답변 (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