How to make 2 data sets the same size

조회 수: 19 (최근 30일)
Angela
Angela 2014년 6월 17일
편집: Madina Makhmutova 2019년 2월 22일
Hello,
I have two data sets (Temperature over Time and Absorption over Time) over the same time interval. The problem is that one set has 6000 values(~10 per second) and the other one 900(~1.5 per second). I would like to cut down both sets to the same size, by taking the average value for each second, but I am not sure how to do this. The function I am writing is getting rather convoluted and confusing with several nested loops, so I am wondering if there is some easy way to do this that I am overlooking.
Thanks in advance for any help, Angela
  댓글 수: 1
Angela
Angela 2014년 6월 18일
Thanks, both ways work fine.

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

채택된 답변

Kevin Claytor
Kevin Claytor 2014년 6월 17일
Have a look at the resample function;
>> help resample
resample Change the sampling rate of a signal.
Y = resample(X,P,Q) resamples the sequence in vector X at P/Q times
the original sample rate using a polyphase implementation. Y is P/Q
times the length of X (or the ceiling of this if P/Q is not an integer).
P and Q must be positive integers.
For example you would be looking at;
time_a = linspace(1,10,900);
time_t = linspace(1,10,6000);
temp = rand(size(time_t))
absorb = rand(size(time_a));
temp_undersampled = resample(temp, length(absorb), length(temp));
size(temp_undersampled)
This is a pretty rough example, and if you want to go the other way, there's interp1 (that's a 1 not an ell) - but the usual caveats apply with interpolation.

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2014년 6월 17일
x1 = randi(500,6000,1); % your data
x2 = randi(600,900,1); %
Fx1 = griddedInterpolant(x1);
Fx2 = griddedInterpolant(x2);
out = [Fx1(linspace(1,numel(x1),600)'), Fx2(linspace(1,numel(x2),600)')];
  댓글 수: 1
Madina Makhmutova
Madina Makhmutova 2019년 2월 22일
편집: Madina Makhmutova 2019년 2월 22일
Dear Andrei,
How can I adjust this code without using for loops if instead of being a vector x1 is a matrix?
x1 = randi(500,6000,5);
Thank you.

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

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by