How to plot the average of the graphs ?

20 次查看(过去 30 天)
Hi,
I have plotted a 3 plots on the same axis and now I want to plot the average of these plots. All my three
vectors that have used have different lenghts. I belive that here we need to interpolate. I want to interpolate my YS3, YS4Q and YS 21Q where I want to use common Lattitude values LatCom, however Im confused becuse I'm not able interploate. Im attaching my plots, code and the error that appeares while interpolating. Im new to matlab and kindly asking for your generous support.
% 3 Combine Plots
P3 = plot(Lat3,YS3, '-r',Lat4Q,YS4Q, '-k',Lat21Q,YS21Q, '-k');
set(P3,{'LineWidth'},{2;1;1});
xlim([-30 30]);
xticks(-30:10:30)
ylim([0 60])
yticks(0:10:50)
grid
box on
ax = gca;
ax.LineWidth = 2;
title('14/01 ~12.20hrs Log +159','FontSize',10)
% Interploate
LatCom = [-30: 0.01: 30]';
y1 = interp1(Lat3,YS3, LatCom); % Im getting a erro as shown below
%Sample points must be unique.
%Error in interp1 (line 188)
%VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);
  2 个评论
the cyclist
the cyclist 2022-8-28
It would be helpful if you uploaded the data in a MAT file. You can use the paperclip icon in the INSERT section of the toolbar.
Vikash Raj
Vikash Raj 2022-8-28
Hi I have attached the data as 'Sample data' please find attached

请先登录,再进行评论。

采纳的回答

Chunru
Chunru 2022-8-28
编辑:Chunru 2022-8-29
load(websave("SampleData", "https://www.mathworks.com/matlabcentral/answers/uploaded_files/1110305/Sample%20data.mat"))
%whos
P3 = plot(Lat3,YS3, '-r',Lat4Q,YS4Q, '-k',Lat21Q,YS21Q, '-k');
set(P3,{'LineWidth'},{2;1;1});
%xlim([-30 30]);
xticks(-30:10:30)
%ylim([0 20])
yticks(0:10:50)
grid
box on
ax = gca;
ax.LineWidth = 2;
title('14/01 ~12.20hrs Log +159','FontSize',10)
LatCom = [-30: 0.01: 30]';
% Interpolation requires unique points
[Lat3u, ia] = unique(Lat3); YS3u = YS3(ia);
y1 = interp1(Lat3u,YS3u, LatCom, 'linear', 'extrap');
[Lat4Qu, ia] = unique(Lat4Q); YS4Qu = YS4Q(ia);
y2 = interp1(Lat4Qu,YS4Qu, LatCom, 'linear', 'extrap');
[Lat21Qu, ia] = unique(Lat21Q); YS21Qu = YS21Q(ia);
y3 = interp1(Lat21Qu,YS21Qu, LatCom, 'linear', 'extrap');
ym = (y1+y2+y3)/3;
hold on
plot(LatCom, ym, 'b', 'LineWidth', 2)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by