trend line not drawing in sub-plot

1 次查看(过去 30 天)
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

采纳的回答

Sean de Wolski
Sean de Wolski 2012-4-24
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 个评论
nori
nori 2012-4-24
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!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fit Postprocessing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by