Matlab plot smoother with interpolation

flatspike — jurgen.strydom on November 21, 2006 at 6:28 pm

21 October 2006

This is a small Matlab program I created for plotting data I took down from experiments in the lab. I hated the edgy look of a normal plain Matlab plot, and drawing by hand is a pain. This m-file takes x points and y points and then creates a smooth graph from it. I used a Matlab interpolation function to achieve this. This file outputs your original data points and the smoothed graph in between. I created a little algorithm that creates a set number of points between each measured point, this solves some issues with log plots.

Normal plot
A normal data plot (ugly!)

Smoothed plot
A smoothed data plot, makes me shed a tear.

References

Mathworks

Files

Plot smoother m-file


Add to:
del.icio.us:Matlab plot smoother with interpolation  digg:Matlab plot smoother with interpolation  reddit:Matlab plot smoother with interpolation

Related:

4 Comments »

  1. Hello, I would just like to express my deepest appreciation for someone actually taking the time to write this wonderful algorithm. In about 4 years of my using MATLAB, I always had to find some roundabount way of smoothing the generated curves. This solution just provided me with a faster, more efficient way of doing this. Thanks! Kind Regards, Akhan Almagambetov.

    Comment by Akhan Almagambetov — February 7, 2007 @ 11:31 pm
  2. Quick note about lines on plots for students: Smoothed plots are all well and fine for making you happy, but remember that you don’t actually have data collected between your points! Literally any line shape between any point is a possibility. Even if you believe that the real phenomena will be smoothly continuous between your collected data points smoothed lines you graph can be misleading. In general it’s better to just not include a line at all.

    Comment by Eric — January 12, 2008 @ 9:58 pm
  3. I would have to say I don’t totally agree with you :-)
    Good practice is to indicate the points where you have collected data as well as drawing your guesstimated line through those points. But in the end it all depends on what kind of data you are working with and what the data is doing to determine if interpolating between data points makes sense or not. Its the students choice, if it’s always a smart one is another lesson to learn :-)

    Comment by jurgen.strydom — January 13, 2008 @ 5:39 am
  4. I would like to thank you for sharing this code. It is very, very helpful in my post-processing of numerical modelling results which vary over few orders of magnitude; I have a massive number of data. In my case, I do know that the points between collected output data vary smoothly; in my case it would be inappropriate to show actual collected data points on my graph, so I disagree with comment #2. Illustration of data points and smoothness of fitted line depend on the context in which they are used.

    Comment by Heather Dye — February 1, 2008 @ 8:27 am

RSS feed for comments on this post. TrackBack URI

Leave a comment

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. | Flat Spike