Spline interpolation of input data
1 回表示 (過去 30 日間)
古いコメントを表示
I would like to obtain a spline interpolation of the following input data contained in the attached txt file. I try to explain how this data needs to be interpolated by describing the txt file:
- The first row of the txt file indicates different number of Reynolds at which the measurements of some variables have been taken. Therefore, the txt file can be split into two subtables: the first goes from column 1 to 4 (Reynolds equal to 60000) and the second goes from column 5 to 8 (Reynolds equal to 100000).
- Each column of the two subtables contains the measurements of a specific variable. In particular, in column 1 there are the measurements of the variable "beta" at Re=60000, column 2 measurements of "CL" at Re=60000, column 3 measurements of "CD" at Re=60000, column 4 measurements of "eff" at Re=60000. Analogously, column 5,6,7,8 contains respectively values of beta, CL, CD and eff at Re=100000.
- Due to the fact that the first row of the txt file contains the Re numbers, the columns of the afore listed variables all started from row number 2.
Plotting the trends of CL,CD and eff with respect to the relative beta, it can be noticed how closed the trend of the variables are and, therefore, I would like to do a spline interpolation between the measurements obtained at 60000 and 100000 Re of CL,CD and eff variables. Unfortunately, as you can see from reading the txt file, the beta at 60000 and 100000 are not the same! Therefore, if, for instance, at row 3, the CL, CD and eff at Re=60000 have been measured for a beta equal to 3, maybe, at the same row, the CL, CD and eff at Re=100000 have been measured for a beta equal to 4. Therefore, the spline interpolation needs to be consistent.
Thak you in advance for your help!!!
2 件のコメント
採用された回答
Mathieu NOE
2021 年 12 月 6 日
hello
check this
not even sure the spline option is really needed here . A basic linear interpolation is good for the job
clc
clearvars
% I would like to obtain a spline interpolation of the following input data contained in the attached txt file.
% I try to explain how this data needs to be interpolated by describing the txt file:
% The first row of the txt file indicates different number of Reynolds at which the measurements of some variables have been taken.
% Therefore, the txt file can be split into two subtables: the first goes from column 1 to 4 (Reynolds equal to 60000)
% and the second goes from column 5 to 8 (Reynolds equal to 100000).
%
% Each column of the two subtables contains the measurements of a specific variable.
% In particular, in column 1 there are the measurements of the variable "beta" at Re=60000,
% column 2 measurements of "CL" at Re=60000,
% column 3 measurements of "CD" at Re=60000,
% column 4 measurements of "eff" at Re=60000.
% Analogously, column 5,6,7,8 contains respectively values of beta, CL, CD and eff at Re=100000.
%
% Due to the fact that the first row of the txt file contains the Re numbers,
% the columns of the afore listed variables all started from row number 2.
% Plotting the trends of CL,CD and eff with respect to the relative beta,
% it can be noticed how closed the trend of the variables are and, therefore,
% I would like to do a spline interpolation between the measurements obtained at 60000 and 100000 Re of CL,CD and eff variables.
% Unfortunately, as you can see from reading the txt file, the beta at 60000 and 100000 are not the same!
% Therefore, if, for instance, at row 3, the CL, CD and eff at Re=60000 have been measured for a beta equal to 3,
% maybe, at the same row, the CL, CD and eff at Re=100000 have been measured for a beta equal to 4.
% Therefore, the spline interpolation needs to be consistent.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% load data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data = readmatrix('Bruining_reviewed.txt');
%% data at Re=60000,
beta1 = data(2:end,1);
CL1 = data(2:end,2);
CD1 = data(2:end,3);
EFF1 = data(2:end,4);
%% data at Re=100000,
beta2 = data(2:end,1+4);
CL2 = data(2:end,2+4);
CD2 = data(2:end,3+4);
EFF2 = data(2:end,4+4);
figure(1)
plot(beta1,CL1,beta1,CD1,beta1,EFF1);
hold on
plot(beta2,CL2,beta2,CD2,beta2,EFF2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% resample all the data on common new beta axis
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
new_beta = linspace(max(min(beta1),min(beta2)),min(max(beta1),max(beta2)),100);
new_CL1 = interp1(beta1,CL1,new_beta,'spline');
new_CD1 = interp1(beta1,CD1,new_beta,'spline');
new_EFF1 = interp1(beta1,EFF1,new_beta,'spline');
new_CL2 = interp1(beta2,CL2,new_beta,'spline');
new_CD2 = interp1(beta2,CD2,new_beta,'spline');
new_EFF2 = interp1(beta2,EFF2,new_beta,'spline');
figure(2)
plot(new_beta,new_CL1,new_beta,new_CD1,new_beta,new_EFF1);
hold on
plot(new_beta,new_CL2,new_beta,new_CD2,new_beta,new_EFF2);
11 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Spline Postprocessing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!