필터 지우기
필터 지우기

How to plot the average of the graphs ?

조회 수: 7 (최근 30일)
Vikash Raj
Vikash Raj 2022년 8월 28일
댓글: Vikash Raj 2022년 8월 29일
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)
  댓글 수: 1
Vikash Raj
Vikash Raj 2022년 8월 29일
Thank you very much. Your codes are working well.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by