Filter löschen
Filter löschen

trend line not drawing in sub-plot

1 Ansicht (letzte 30 Tage)
nori
nori am 24 Apr. 2012
Hello,
I have this really strange issue going and it is really confusing me. I am trying to plot a trend line through a set of data and I can do it just fine in a regular plot, but as soon as I add it to a sub-plot, I can get either the data or the trend line and not both.
I did try to do it with the toolbox but in a subplot figure, I can only get 1 trend line to show up on any of my 5 subplots at a given time. so both methods are 'either or' and not both :(
any help would be greatly appreciated. thanx.
here is my code i am testing with.
a = [1 2 3 4 5]';
b = [3 7 9 3 7]';
figure
hold all
plot (a,b);
% plot trend line
f = fittype('a*x+b'); %define fittype
fitobj = fit(a,b,f); %fit line to data
plot (fitobj,'k') %plot trend line
figure
subplot(2,1,1)
plot (a,b);
% plot trend line
f = fittype('a*x+b'); %define fittype
fitobj = fit(a,b,f); %fit line to data
plot (fitobj,'k') %plot trend line

Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 24 Apr. 2012
You need to hold on to your subplot!
figure
subplot(2,1,1)
hold on
plot (a,b);
% plot trend line
f = fittype('a*x+b'); %define fittype
fitobj = fit(a,b,f); %fit line to data
plot (fitobj,'k') %plot trend line
  1 Kommentar
nori
nori am 24 Apr. 2012
jeez. i have been whacking at that problem for 2 hours!! i did try putting the 'hold' after the figure but i didnt try after the 'subplot'
thanks so much!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by