Borrar filtros
Borrar filtros

How to plot the average of the graphs ?

7 visualizaciones (últimos 30 días)
Vikash Raj
Vikash Raj el 28 de Ag. de 2022
Comentada: Vikash Raj el 29 de Ag. de 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 comentarios
the cyclist
the cyclist el 28 de Ag. de 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 el 28 de Ag. de 2022
Hi I have attached the data as 'Sample data' please find attached

Iniciar sesión para comentar.

Respuesta aceptada

Chunru
Chunru el 28 de Ag. de 2022
Editada: Chunru el 29 de Ag. de 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)
  1 comentario
Vikash Raj
Vikash Raj el 29 de Ag. de 2022
Thank you very much. Your codes are working well.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by