필터 지우기
필터 지우기

Replicating values a certain number of times

조회 수: 2 (최근 30일)
Muneer
Muneer 2013년 12월 3일
답변: Andrei Bobrov 2013년 12월 3일
Hello, I have a long array of data from 0 to 1959 in steps of 1. Is there any way to expand that data so that each value repeats x number of times? ie. if x is 4
new = 0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3...
I have compressed data and I want to be able to expand it with this approximation.
Thanks for your help!

채택된 답변

Wayne King
Wayne King 2013년 12월 3일
편집: Wayne King 2013년 12월 3일
There are a number of ways to do this.
One way use a constant interpolator:
x = 0:9;
h = ones(4,1);
xnew = zeros(40,1);
xnew(1:4:end) = x;
y = filter(h,1,xnew);
Another way use repmat()
x = (0:9)';
x = (repmat(x,1,4))';
x = reshape(x,40,1);

추가 답변 (2개)

sixwwwwww
sixwwwwww 2013년 12월 3일
편집: sixwwwwww 2013년 12월 3일
try this:
x = 1:100; % Values to be repeated
a = 4; % Number of times each value is repeated
b = repmat(x, 4);
b = reshape(b, 1, []); % Final result

Andrei Bobrov
Andrei Bobrov 2013년 12월 3일
Jos (10584)'s idea:
k = 1959;
n = 4;
x = floor((0:(k+1)*n-1)/n);

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by