0

I have a data set called curvefit and the following code plot(curvefit,'b-')

When this code is plotted I get this plot image

http://tinypic.com/r/fu7yo3/8

However when I try to do a subplot with subplot(2,1,1); plot(curvefit,'b-') I get this (actual subplot code to produce image uses subplot(1,1,1) to create larger image, result is the same)

http://tinypic.com/r/6dsgth/8

I've cleared my workspace of any extraneous variables, used clf beforehand. Hold on is not on, these plots are plotted seperately. I'm not sure what's going on or how to fix this. Thanks to anybody who can! Here is my code if it helps

 figure
 set(gcf, 'Position', get(0,'Screensize'));
 span=61; 
 smooth349=smooth(updisplacementP349,span);
 subplot(2,1,1); plot(upliftdatesP349,smooth349,'b-')
 datetick('x')

 curvefit349=fit(upliftdatesP349',smooth349,'sin4');
 subplot(2,1,2); plot(curvefit349,'b-');

upliftdatesP349 is a 1 by 3038 row of dates with each date taken per day

updisplacementP349 is a 3038 by 1 vector of data. I'm new to stack overflow so I am not sure what the procedure is on posting exact code because mine pulls data from large text files which I can't post.

3
  • What are the dimensions for curvefit? Is it a matrix with two columns? I've never tried to plot matrices before and would do something like plot(curvefit(:,1),curvefit(:,2),'b-') instead. When I tried the matrix form (first column x, and second column sin(x)) I did get a weird plot showing the sine wave and a diagonal line (much like yours). Check the plot with matrix link for info on plotting in this manner. You may want to just stick with the plotting of the individual columns. Commented Jun 20, 2014 at 4:04
  • Please, post the full code, so that we can exactly recreate your case Commented Jun 20, 2014 at 4:32
  • curvefit is a 1x1 cfit value outputted by the fit command. The default way of plotting a cfit value as given by MATLAB documentation here mathworks.com/help/curvefit/curve-fitting.html is the way I described in my original question. Commented Jun 20, 2014 at 4:40

1 Answer 1

1

Try this, it's not exactly what you are after but you can turn off the other curve.

load hahn1
f = fit( temp, thermex, 'rat23' )
subplot(2,1,1);
h= plot(f,1:size(thermex),thermex);
set(h(1),'Visible','off');
subplot(2,1,2);
h= plot(f,1:size(thermex),thermex);
set(h(2),'Visible','off');

As for your example try this:

subplot(2,1,1);
h= plot(curvefit349,1:size(upliftdatesP349),upliftdatesP349);
set(h(1),'Visible','off');
subplot(2,1,2);
h= plot(curvefit349,1:size(upliftdatesP349),upliftdatesP349);
set(h(2),'Visible','off');

I think your problem could possibly be a bug in Matlab but the workaround above should work fine.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the comment. I found a work around that is similar to yours. I've never encountered an actual "bug" in MATLAB before so I wasn't sure what to expect. There must be a way to get it to work the way it is. Until then though. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.