How to interpolate when we have two different sizes
22 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
Someone would be kind enough to help me how to do an interpolation when we have two different sizes being A and B.
I will do interpolation A and B then concatenate the result as follows interpolation_A_B= [interpolation_A, interpolation_B].
Here is my code:
%% Data
A=[0,-2.24489741646952,-4.62733420618208,-6.95719767650665,-9.01707651070867,-10.6031942911103,-11.5925433634751,-11.8888513183929,-11.4910074241661,-10.3269616567176,-8.37131286980876,-5.73036557765802,-2.73380439351284,0.0658350852258175,2.24268430772633,3.60945691919934,4.23841606693665,4.38617345954930,4.33237937220543,4.24478638091837,4.11981257851839,3.91272625898743,3.64047136322393,3.40598831808841,3.35826429186336,3.50296413009803,3.66772774367983,3.56377296314676,2.91695995975226,1.61068736575304];
temps_A=[10,56,103,149,196,242,289,335,382,428,475,521,568,614,661,707,754,800,847,893,940,986,1033,1079,1126,1172,1219,1265,1312,1358];
B=[0,0.266260173065289,-0.0707528123775336,-1.10727656343698,-2.67932011084229,-4.49683089873686,-6.28901889839069,-7.86823684856092,-9.10292224756012,-9.93528552429639,-10.3943919840282,-10.6200553018127,-10.6751851242251,-10.4946119723262,-9.93187689931717,-8.79370001488421,-7.21878022731030,-5.48155200603622,-3.92374944116942,-2.83303212357369,-2.34292583956979,-2.31255526161581,-2.51444122441427,-2.69362744473124,-2.68977697021639,-2.43432161929766,-1.93071631270870,-1.25144435000955,-0.517481281517809,-1.93071631270870,-1.25144435000955,-0.517481281517809];
temps_B=[10,41,72,104,135,166,198,229,260,292,323,354,386,417,448,480,511,542,574,605,636,668,699,731,762,793,825,856,887,918,949,980,1011];
%% interpolation A
time_interpolation_A=min(temps_A):1:max(temps_A);
A_interpolation = interp1(temps_A,A,time_interpolation_A);
%% interpolation B
time_interpolation_B=min(temps_B):1:max(temps_B);
B_interpolation = interp1(temps_B,B,time_interpolation_B);
%% concatenate interpolation A & B
Interpolation_A_B=[A_interpolation,B_interpolation];
0 个评论
采纳的回答
Star Strider
2021-6-2
A=[0,-2.24489741646952,-4.62733420618208,-6.95719767650665,-9.01707651070867,-10.6031942911103,-11.5925433634751,-11.8888513183929,-11.4910074241661,-10.3269616567176,-8.37131286980876,-5.73036557765802,-2.73380439351284,0.0658350852258175,2.24268430772633,3.60945691919934,4.23841606693665,4.38617345954930,4.33237937220543,4.24478638091837,4.11981257851839,3.91272625898743,3.64047136322393,3.40598831808841,3.35826429186336,3.50296413009803,3.66772774367983,3.56377296314676,2.91695995975226,1.61068736575304];
temps_A=[10,56,103,149,196,242,289,335,382,428,475,521,568,614,661,707,754,800,847,893,940,986,1033,1079,1126,1172,1219,1265,1312,1358];
B=[0,0.266260173065289,-0.0707528123775336,-1.10727656343698,-2.67932011084229,-4.49683089873686,-6.28901889839069,-7.86823684856092,-9.10292224756012,-9.93528552429639,-10.3943919840282,-10.6200553018127,-10.6751851242251,-10.4946119723262,-9.93187689931717,-8.79370001488421,-7.21878022731030,-5.48155200603622,-3.92374944116942,-2.83303212357369,-2.34292583956979,-2.31255526161581,-2.51444122441427,-2.69362744473124,-2.68977697021639,-2.43432161929766,-1.93071631270870,-1.25144435000955,-0.517481281517809,-1.93071631270870,-1.25144435000955,-0.517481281517809];
temps_B=[10,41,72,104,135,166,198,229,260,292,323,354,386,417,448,480,511,542,574,605,636,668,699,731,762,793,825,856,887,918,949,980];
Data = [size(A); size(B)]
Create new temperature vectors from the existing vectors, and interpolate.
NewLength = 50;
NewAt = linspace(min(temps_A), max(temps_A), NewLength);
Anew = interp1(temps_A, A, NewAt)
NewBt = linspace(min(temps_B), max(temps_B), NewLength);
Bnew = interp1(temps_B, B, NewBt)
figure
plot(temps_A, A, '.-b')
hold on
plot(NewAt, Anew, '.r')
hold off
grid
legend('Original', 'Interpolated', 'Location','best')
title('A')
figure
plot(temps_B, B, '.-b')
hold on
plot(NewBt, Bnew, '.r')
hold off
grid
legend('Original', 'Interpolated', 'Location','best')
title('B')
legend('Original', 'Interpolated', 'Location','best')
.
4 个评论
更多回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!