Compass Axis Problem

4 views (last 30 days)
Rasmus Lundgaard Christensen
Hi again,
Since my last post, i managed to "animate" the heading of a submarine through a Simulink model and the following code: (where ang_rad is an array of angles the submarine is having and vel_Y is an array of velocities - both of the same length).
[theta,rho] = pol2cart(ang_rad,vel_Y);
for j = 1:length(vel_Y)
theta_n = theta(j);
rho_n = rho(j);
h1 = compass(theta_n,rho_n);
refreshdata(h1,'caller');
drawnow;
end
The problem is now, that everytime the plot get's refreshed, the axis of the plot changes, and hence it is a plot of the angle and velocity - which in turn is to run real-time (during simulations) it could be nice if the axis weren't subject to change everytime a new entry is added.
Is there a way to handle this? I've tried different methods like set(h1,'XLim' ....) and the sort - but that did not help me - i might have placed it wrong in the loop. But hopefully any of you knows how it is done.
Thanks in advance :)
  1 Comment
Wayne Gilbert
Wayne Gilbert on 18 Jan 2013
Hi I'm suffering with the same problem too!
I want to be able to plot a number of compass plots but I can't find any way to 'fix' the axis so that they are set to the maximum of the data within the vector that contains the magnitude.
I'm a very new user of MatLab and am struggling to get this working for a project.
Can anybody out there help? :)

Sign in to comment.

Answers (1)

Wayne Gilbert
Wayne Gilbert on 18 Jan 2013
Being new to MatLab, I tried looking for an answer to this with similar plots and was pleased to find this solution to a similar question for polar plots by Patrick Kalita on 7th June 2011...
Answer by Patrick Kalita on 7 Jun 2011
Accepted answer
Well, unfortunately there's no direct way to do it. But you can cheat (yay! cheating!). Let's say you know you want to have the radial dimension go out to 2. You can add a line of constant radius and then make it invisible:
t = 0 : .01 : 2 * pi;
P = polar(t, 2 * ones(size(t)));
set(P, 'Visible', 'off')
Now you can add the data you actually want to plot:
hold on polar(t, sin(2 * t) .* cos(2 * t), '--r')
By plotting a single cartesian vector of magnitude = the scale that you want in white and then setting hold on, this appears to do the trick!
Happy to hear of any better solutions which don't 'cheat'!!
  1 Comment
Claudia
Claudia on 30 Jan 2013
Hi,
this answer helped my quite a lot.
Unfortunately it only works for one plot on a figure but not for subplots.
Do you have any idea why? And what do I have to do to get it work for subplots?
Thanks so much, Claudia

Sign in to comment.

Categories

Find more on Marine and Underwater Vehicles 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!