How to plot the average plot out of three plots

Hello everyone, i have extracted the data from the excel to plot the graphs .Now , i want to plot the average plot in the same graph .i have three plots in the same graph which each of the three has different 1 column but different rows.i would be grateful if anyone could help me to get the idea of how to plot that graph.Thank you in advance.

 채택된 답변

KSSV
KSSV 2020년 8월 26일

0 개 추천

You should decide the x-axis same for all the data and make y-values NaN for out of odmain/ extrapolation range and use mean/ nanmean.
  1. Check the dimensions of each data.
  2. Fix the common x-axis data to get the all the data to this x-axes. I would pick the data1, as it covers the more range of x-axes when compared to other data.
  3. Get the data2, data3 to the x-axes domain of data1.
  4. Use interp1 to get the data2, data3 to the x-axes range of data1. The extrapolation points should be set to NaN.
  5. Use nanmean or mean nan flags to get the avarage of data1, data2 and data3.

댓글 수: 6

DEWDROP
DEWDROP 2020년 8월 26일
Thank you for reply but how to interp the data.when i went throught the matlab help section ,it says vq=interp1(x,v,xq).its not clear what the v is supposed to be.
KSSV
KSSV 2020년 8월 26일
Your data1, data2, data3 has both (x,y) respectively right? So the y value of each data goes to v.
I have tried to write code from the internet.can you please help me to correct it as i am the beginner on matlab. i tried to run the code written below but it said it has errors.Appreciate your help
clc
clear all
load=xlsread('steelgraph.xlsx','D2:D3042');
disp=xlsread('steelgraph.xlsx','E2:E3042');
plot(disp,load)
xlabel('displacement(mm)')
ylabel('load(KN)')
title('steel(2%)')
grid on
hold on
load1=xlsread('steelgraph.xlsx','J2:J1795');
disp1=xlsread('steelgraph.xlsx','K2:K1795');
plot(disp1,load1)
hold on
load2=xlsread('steelgraph.xlsx','O2:O1906');
disp2=xlsread('steelgraph.xlsx','P2:P1906');
plot(disp2,load2)
legend
xavg=linspace(0,0.01,2.3);
y1avg=interp1(disp(:),load(:),xavg(:),'linear');
y2avg=interp1(disp1(:),load1(:),xavg(:),'linear');
y3avg=interp1(disp2(:),load2(:),xavg(:),'linear');
y_avg=mean([y1avg y2avg,y3avg],3);
figure
plot(xavg ,y_avg)
KSSV
KSSV 2020년 8월 27일
Wahat error you are getting? You should attach your files to check the code for error.
DEWDROP
DEWDROP 2020년 8월 27일
KSSV
KSSV 2020년 8월 27일
Why don't you attach all your data in a mat file..

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

추가 답변 (1개)

DEWDROP
DEWDROP 2020년 8월 28일

0 개 추천

HERE ,i have attached the excel as well s mat file.Thank you for your continuous help

댓글 수: 2

load("Data.mat")
x1 = data(:,2) ;
y1 = data(:,1) ;
%
x2 = data(:,4) ;
y2 = data(:,3) ;
%
x3 = data(:,6) ;
y3 = data(:,5) ;
plot(x1,y1,x2,y2,x3,y3)
hold on
plot(x1,[y1+y2+y3]/3) ;
legend('data1','data2','data3','average')
DEWDROP
DEWDROP 2020년 8월 28일
Data.mat is not able to open .and also data 2 and data 3 has not the ssame value so we need tto interpolate?

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

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

질문:

2020년 8월 26일

댓글:

2020년 8월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by