linear interpolation of matrix.
Afficher commentaires plus anciens
Hi,
I'm new to matlab so this might be very simple but I would appreciate the help..
I have a matrix of 32 values across and 2209 down. Each line represents one hour of rainfall so these values represent values of rainfall at 1.875min timesteps. I need to use linear interpolation to make this either 2min or 5 min timesteps (a matrix of 30 values across or 12 values across).
for example, trying to convert the 32x2209 into 30x2209.
The new first value would be 0.9375 * the original first value.
The new second value would be (0.0625 * the original first value) + ((0.9375 - 0.0625) * the original second value)
The new third value would be ((2 * 0.0625) * the original second value) + ((0.9375 - (2 * 0.0625)) * the original third value)
... and so on.
Is there an easy way to do this in matlab?
Many thanks in advance to anyone that can help.
Patrick.
1 commentaire
Réponse acceptée
Plus de réponses (2)
Matt J
le 18 Nov 2012
0 votes
Use the INTERP1 command
Ilham Hardy
le 19 Nov 2012
A beginner approach,
%1.875 is the default sample rate
n_col_def = (60/1.875);
%row amount
n_row_def = 2209;
%create time vector of original data (start from t = 1.875, hop 1.875,until data end)
time_1 = (60/n_col_def):(60/n_col_def):(60/n_col_def)*n_row_def*n_col_def;
%your matrix name
data_1 = rand(n_col_def,n_row_def);
%transpose the matrix to get correct reshape
data_1_tr = data_1';
%reshape matrix to vector (1*n)
data_1_res = reshape(data_1_tr,1,n_row_def*n_col_def);
% same row amount with 30 columns require lemgth n_time_2 to be specific
n_col_new = (60/2);
n_time_new = n_col_new*n_row_def;
%t_start = 2,sample time 2 minutes . [2,4,6...,]
time_2 = 2:2:(n_time_new*2);
%interpolate the data based on the new time vector (of 5 minutes)
data_2 = interp1(time_1,data_1_res,time_2,'linear');
% reshape vector to matrix
data_2_res = reshape(data_2,n_col_new,[]);
data_2 = data_2_res';
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!