Graph coordinates with error bars and another function in same plot
2 views (last 30 days)
Show older comments
Hi, I'm tying to create a graph consisting of (1) data points with the same x error bars and teh same y error bars for all of the data points (but e error bars are not the same as y error bars) and (2) the curve of best fit for these data points.
Data = ...
[3.66 98.8
4.38 109.8
5.42 124.7
6.60 140.8
8.02 156.8
-3.39 -95.9
-4.57 -113.9
-5.39 -125.2
-7.14 -147.1
-9.05 -168.6
0 0]
xerror = .01;
yerror = .1;
%error values are in mA
%x = Data(:,1);8.02
%y = Data(:,2);
% plot(t,y,'ro');
x = [3.66 4.38 5.42 6.60 8.02 -3.39 -4.57 -5.39 -7.14 -9.05];
y = [98.8 109.8 124.7 140.8 156.8 -95.9 -113.9 -125.2 -147.1 -168.6];
xnew1 = sort(x);
ynew1 = sort(y);
xnew2=xnew1;
ynew2=ynew1;
x= -10:1e-2:10;
y = -200:1e-2:200;
yneg= [.1 .1 .1 .1 .1 .1 .1 .1 .1 .1];
ypos= [.1 .1 .1 .1 .1 .1 .1 .1 .1 .1];
xneg = [.01 .01 .01 .01 .01 .01 .01 .01 .01 .01];
xpos = [.01 .01 .01 .01 .01 .01 .01 .01 .01 .01];
y = 30.13.*x.^9-1.724.*x.^8-144.2.*x.^7+9.357.*x.^6+258.9.*x.^5-14.95.*x.^4-233.9.*x.^3+10.48.*x.^2+226.9.*x-5.334
plot(x,y,'g-');
errorbar(xnew1,ynew1,yneg,ypos,xneg,xpos,'r.');
grid on
title('Voltage v. Current');
xlabel('Voltage [V]');
ylabel('Current [mA]');
legend({'errorbars''Polynomial Model'});
I can get either the plot or the errorbar but not both. Is tehre some way I can get bot overlapping each other, with the errorbar plot ontop of the curve of best fit.
BTW the curve of best fit was creates using MATLAB's curve fitting tool. In the graph previow in the fitting tool I was able to see both the points and teh curve (but not the error bars)
It is also desirable to have a key indicating both the curve and errorbars
2 Comments
dpb
on 5 Mar 2019
To add more to a given plot, use
hold on
after the first plotting command. See
doc hold
for examples, more info...
doc legend % for the other part of the question
Answers (0)
See Also
Categories
Find more on Errorbars in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!