The following MATLAB codes are also compatible with GNU Octave (I used the version 3.8.1).

This is the final function I wrote:

1 2 3 4 5 6 7 8 9 10 11 12 13 |
function [] = massplot(x,y,m,t,xdim,ydim) [rowsize,colsize]=size(x); dim=m*(15/max(m)); for col=1:colsize for row=1:rowsize scatter(x(row,col),y(row,col),dim(row,1),'k','filled'); hold on; axis([xdim ydim]); end pause(t); hold off; end end |

Note: since I want to plot bigger points for bigger masses, I intentionally limited the maximum mass dimension to 15. It means all other masses are also scaled proportionally.

Let’s take a look to the parameters:

**x (or y) **– it contains the sequences of all x(*or y*)-positions of all masses. The n^{th}-row corresponds to the n^{th}-mass and the m^{th}-column represents its m^{th}-position along x(*or y*)-axes.

**m **– mass of the point.

**t **– time (in seconds) between one position and the next one.

**xdim (or ydim) **– it specifies the lower and upper limits of the x(*or y*)-axes.

Example

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
%we define here 3 masses m=[600;400;800]; %and a set of 50 positions x1=1:50; y1=4*x1; y2=x1; y3=0.5*x1.^2; %now the input parameters x=[x1;x1;x1]; y=[y1;y2;y3]; t=0.01; xdim=[0 100]; ydim=[0 1300]; %we call the function massplot(x,y,m,t,xdim,ydim); |

Remember to use *addpath* containing the address of the massplot function file if this example’s script doesn’t findĀ it.

This is the result:

Alternatively you can make use of the *plot* function just changing the *scatter*‘s line with the following*:*

1 |
plot(x(row,col),y(row,col),'ok','MarkerSize',dim(row,1),'MarkerFaceColor','k'); |

Why I used the *scatter* function instead of *plot*? Because it looks to be faster here. I tried this example on GNU Octave 3.8.1 using first *scatter* and than *plot. *I just deleted the line with pause(t) and called the massplot function ten times (using a for loop). I measured the performance by writing *tic* before the loop and *toc* right after that. Result? “Elapsed time is 35.6928 seconds” for *scatter*, “Elapsed time is 40.7051 seconds” for *plot*. Successive tests give very similar results.

## Leave a Reply