Matlab plot smoother with interpolation
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.

A normal data plot (ugly!)

A smoothed data plot, makes me shed a tear.
References
Files
4 Comments »
RSS feed for comments on this post. TrackBack URI



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.
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.
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
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.