How to plot the average of the graphs ?

20 visualizzazioni (ultimi 30 giorni)
Vikash Raj
Vikash Raj il 28 Ago 2022
Commentato: Vikash Raj il 29 Ago 2022
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 Commenti
the cyclist
the cyclist il 28 Ago 2022
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 il 28 Ago 2022
Hi I have attached the data as 'Sample data' please find attached

Accedi per commentare.

Risposta accettata

Chunru
Chunru il 28 Ago 2022
Modificato: Chunru il 29 Ago 2022
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)

Più risposte (0)

Categorie

Scopri di più su Graphics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by