필터 지우기
필터 지우기

How to repeat the matrix to complete the shape of Matrix

조회 수: 4 (최근 30일)
Stephen john
Stephen john 2022년 4월 11일
댓글: Walter Roberson 2022년 4월 11일
Hello everyone i hope you are doing well.
I have the following Dataset,
one has shape of 1x586 and other has shape 1x48.
I want to repeat this matrix to to complete the shape of 1x1000 and 1x10000.
How can i do this in MATLAB
  댓글 수: 1
Rik
Rik 2022년 4월 11일
What have you tried so far?
Also, 48 and 586 are not integer fractions of 1e3 and 1e4. How do you want to deal with that?

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

답변 (1개)

Walter Roberson
Walter Roberson 2022년 4월 11일
Your requirements are not clear.
targetsize586 = 10000;
n586 = numel(Mat_586);
nrep = targetsize586 / n586;
fullrep = floor(nrep);
leftover = targetsize - fullrep * n586;
variation1 = [repmat(Mat_586, 1, fullrep), Mat_586(1:leftover)];
variation2 = repelem(Mat_586, 1, ceil(nrep)); variation2(targersize586+1:end) = [];
variation1 makes repeated copies of the matrix, like [1 2 3, 1 2 3, 1 2 3, 1 2 3, ...] as many times as possible to fit within the target size, and then makes a partial copy as large as needed to fit.
variation2 makes repeated copies of the elements, like [1 1 1 1, 2 2 2 2, 3 3 3 3, ...] with each element repeated as many times as needed until the overall would meet or exceed the target size, and then trims off enough copies of the last element to make the overall fit. So you might, for example, get 21 copies in a row of each value except the last, followed by (say) 18 copies of the last element.
  댓글 수: 8
Stephen john
Stephen john 2022년 4월 11일
@Walter Roberson let me explain it to you , let my dataset shape 1176
The first row contain 1000 samples and they repeat copies of the matrix upto 10000 to complete 1st row
the n in second row 176 samples and they should repeat copies of the matrix upto 10000 to complete second row..
the output shape is 2x10000
Walter Roberson
Walter Roberson 2022년 4월 11일
targetsize = 10000;
output = [];
temp = reshape(YourData, 1, []); %ensure row
nt = numel(temp);
while nt >= targetsize
output = [output; temp(1:targetsize)];
temp = temp(targetsize+1:end);
nt = numel(temp);
end
nrep = ceil(targetsize / nt); %we know nt < targetsize at this point
temp = repmat(temp, 1, nrep);
output = [output; temp(1:targetsize)];

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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by