Compass Plot Animation

5 views (last 30 days)
Rasmus Lundgaard Christensen
Hi,
I've been trying to use the compass plot - to plot different angles and velocities accordingly. I've searched the help community and the web, but it seems that no body have tried it before - at least not to make matlab do it.
It is a simulation of a submarine model, which loads data into different *.mat files, which is then used for the plot. What we need to do, is to refresh the compass plot, so it updates and loads a new set of data (the next data in the array) - and only contains one arrow at a time. Is this possible at all?
I hope you are catching my drift - and are able to help! In advance thanks :)
  2 Comments
Jan
Jan on 15 Nov 2011
Yes, this is possible. What have you tried so far and which specific problem do you have?
Rasmus Lundgaard Christensen
Hi Jan,
I am able to "automate" the plot. But i now run into another problem. The code i am using, is the example used in refresh data. The problem now, is that it plots the wrong things on the axes.
The length of the vector should represent the velocity, and the angle of it, should represent the angle of the submarine. The below code does plot the function automatically, but it uses the wrong axes (eg. the wrong things are converted into lengths and angles).
I hope you get it? Otherwise just let me know :)
[x,y] = pol2cart(ang_X,ang_Y);
for j = 1:length(vel_Y)
x2 = ang_Y(j);
y2 = vel_Y(j);
h1 = compass(x2,y2)
refreshdata(h1,'caller');
drawnow;
end

Sign in to comment.

Answers (1)

Rasmus Lundgaard Christensen
I had made the mistake of not using the "new" array created by pol2cart, as well as not converting into radians. (some major mathematical mistakes...). But now it works.
Therefore - the code used to generate the animated graph, is:
ang_rad = ang_Y * pi/180;
[x,y] = pol2cart(ang_rad,vel_Y);
axis off, axis equal
for j = 1:length(vel_Y)
x2 = x(j);
y2 = y(j);
h1 = compass(x2,y2)
refreshdata(h1,'caller');
drawnow;
end
I hope this can help somebody else wanting to plot the direction of bodies - according to the velocity :)

Categories

Find more on Animation in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!