display errorbar on each point in the curve matlab code

4 views (last 30 days)
I have data point of two curves in one graph as follows
x=[2,4,6,8,10];
y1=[58.87 168 366 670.48 715];
y2=[51 147 327 525 645.69 ] ;
I want to display "errorbar" on each point for each curve with legend in one graph.
Please can anyone help me ?
Thanks in advance.
  3 Comments
Saurabh Patel
Saurabh Patel on 13 May 2023
% User Data Collection
x=[2,4,6,8,10];
y1=[58.87 168 366 670.48 715];
y2=[51 147 327 525 645.69 ];
% define the error for eact errorbar
err_y1=30*ones(size(y1));
err_y2=25*ones(size(y2));
% Two Y-axis on same Plot
yyaxis left
errorbar(x,y1,err_y1,'LineWidth',2)
ylabel('Data of Y1');
xlabel('X-axis');
yyaxis right
errorbar(x,y2,err_y2,'LineWidth',2)
ylabel('Data of Y2');
% Insert Legend
labels={'Data of Y1','Data of Y2'};
legend(labels,'Location','northwest','Orientation','vertical');

Sign in to comment.

Accepted Answer

Saurabh Patel
Saurabh Patel on 13 May 2023
% User Data Collection
x=[2,4,6,8,10];
y1=[58.87 168 366 670.48 715];
y2=[51 147 327 525 645.69 ];
% define the error for eact errorbar
err_y1=30*ones(size(y1));
err_y2=25*ones(size(y2));
% Two Y-axis on same Plot
yyaxis left
errorbar(x,y1,err_y1,'LineWidth',2)
ylabel('Data of Y1');
xlabel('X-axis');
yyaxis right
errorbar(x,y2,err_y2,'LineWidth',2)
ylabel('Data of Y2');
% Insert Legend
labels={'Data of Y1','Data of Y2'};
legend(labels,'Location','northwest','Orientation','vertical');

More Answers (0)

Community Treasure Hunt

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

Start Hunting!