Why don't I see the graph? [No Graph visible in figure window without '+' or '.' argument]

28 views (last 30 days)
The file that is attached is an attempt on simulating a swing-by. However all I get at the end is an empty figure window.
Funnily enough I am able to see the graphs when I add a marker like '+' or '.' to my plot, so they get simulated at least. Leaving the LineSpec out of the plot or adding a Line-Style like '-' or '--' will result in an invisible graph.
It seems to run on the computer of my teacher but not on my macbook pro nor on my desktop pc. He is using a very old version of Matlab and I am currently on R2015b.
EDIT: I changed the description of my problem slightly.

Accepted Answer

Mike Garrity
Mike Garrity on 7 Dec 2015
When you're calling plot, you're passing in a single data point.
The linespecs '.', '+', etc. are setting the property Marker. That means that they're controlling what symbol gets drawn at each data point.
The linespecs line '-', ':', etc. are setting the property LineStyle. That means that they're controlling how lines get drawn which connect adjacent data points. Since you only have one data point, this is rather problematic in your case. If you want to draw lines connecting the points, then you really need to save the previous data point and pass two into your call to plot.
You can learn more about linespecs on this page of the documentation.
You might also want to learn about the new animatedline function, which is designed to do exactly the type of thing that you're doing here. However it was introduced in R2014b, so it won't work in that older version.
  2 Comments
Andreas Gschwendtner
Andreas Gschwendtner on 10 Dec 2015
Thank you very much! Replacing the plot with the animatedline function actually worked. Maybe you can help me with another question of mine. Is there a way to add a comet to the animatedline? The comet function is not working as well but I'd really like to have the current position of my planets displayed.
Mike Garrity
Mike Garrity on 10 Dec 2015
If you mean a marker on the head of the line, the animatedline object won't do that for you. You need to add another object to do that part.
I took your code and added the following near where you initialized the waitbar.
hmars_line = animatedline('Color','red');
hmars_marker = line(nan,nan,'Marker','o','Color','red');
hsonde_line = animatedline('Color','blue');
hsonde_marker = line(nan,nan,'Marker','d','Color','blue');
axis equal
xlim([-3.3e11 2.4e11])
ylim([-2.25e11 2.25e11])
and I replaced your calls to plot with this:
hmars_line.addpoints(X_Mars(1,:),X_Mars(2,:));
hmars_marker.XData = X_Mars(1,:);
hmars_marker.YData = X_Mars(2,:);
hsonde_line.addpoints(X_Sonde(1,:),X_Sonde(2,:));
hsonde_marker.XData = X_Sonde(1,:);
hsonde_marker.YData = X_Sonde(2,:);
The result looks like this:

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 29 Nov 2015
Try moving the "hold on" to after the first plot3()
In R2014b and later, "hold on" becomes the same as "hold all", but that can have the effect of freezing the axes limits, so if you "hold on" before you have plotted anything then you might not be able to see the output.
  1 Comment
Andreas Gschwendtner
Andreas Gschwendtner on 29 Nov 2015
thank you for your reply. Unfortunately it did not change anything. I will add a picture where you can see the plots using '.'
I could work with that but it would be a lot better if I had a real line graph instead of many dots. If I remove any '.' arguments the graphs simply disappear. I changed the file a bit so I will attach the new one in this post.

Sign in to comment.

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!