How to display the data points on my graph?
90 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Cheng-Han Yang
am 21 Mär. 2019
Beantwortet: Kelly Kearney
am 21 Mär. 2019
filename='data3.txt';
headlines=0;
delim='\t';
B=importdata(filename,delim,headlines);
t=B(:,1);
y=B(:,2);
fun = @(x,t)x(1)*t.^3 + x(2)*t +6;
x0=[1 1];
x=lsqcurvefit(fun, x0, t, y);
scatter(t,y);
fprintf('Function fitted is y = %5.3f x^3 + %5.3f x + 6\n', x(1), x(2));
fplot(@(t)x(1)*t.^3 + x(2)*t +6, [B(1,1) B(10,1)]);
The above is my code. The scatter command works as usual when I get rid of the fplot command, but fplot seems to overwrite the scatter part and does not show me the data points anymore.
Thanks in advance.
0 Kommentare
Akzeptierte Antwort
Kelly Kearney
am 21 Mär. 2019
Add a hold after your scatter plot:
scatter(rand(10,1), rand(10,1));
hold on
fplot(@(x) x, [0 1])
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Scatter Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!