
Plotting noncontinuous arc segments
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Guy Lalkin
am 15 Apr. 2015
Kommentiert: Guy Lalkin
am 16 Apr. 2015
Hey all,
I am trying to plot a non-continuous arc of a circle, given the center, radius and angle ranges of the arc(s). For instance, say I want to plot the following angle range:
0,...,0.75*pi,1.25*pi,...,2*pi
There's a gap between 0.75*pi and 1.25*pi. I don't want MATLAB to plot anything "between" these two angles, but it plots a straight vertical line.
This the basic structure of my code:
t=[];
for theta=0:0.01:2*pi
if % irrelevant condition that decides if the arc covers this angle
t=[t theta];
end
end
plot(a1*cos(t),a1*sin(t),'b--')
And here is the figure:

I want to 'skip' the vertical line. Is this possible?
Any kind of assistance would be greatly appreciated!
0 Kommentare
Akzeptierte Antwort
John D'Errico
am 15 Apr. 2015
Bearbeitet: John D'Errico
am 15 Apr. 2015
You ARE plotting 0 to 2*pi. That is 360 degrees. You have an x,y, pair at EVERY one of those points. Then you pass those numbers to plot. How should it know that even though you told it to plot those points, that you don't really mean it?
You CAN buy the mind reading toolbox when it comes out, but I hear that it will be incredibly expensive.
Better is to not create values for t for those points. Simpler is to fill t with NaNs when that test fails.
Finally, BEST is to preallocate your array in advance. This will be seriously faster. And one day if you never learn to preallocate your vectors and arrays in cases like this, you will come back to this forum, and ask why is your code SOOOOO slow!
theta = 0:0.01:2*pi;
t = theta;
for ind = 1:numel(theta)
if % irrelevant condition that decides if the arc does NOT cover this angle
t(ind) = NaN;
end
end
plot(a1*cos(t),a1*sin(t),'b--')
Better yet would be to build t in a vectorized way, but since you have told us nothing more than that the test is irrelevant, I can't help you there. It might be something as simple as this:
t = linspace(-3*pi/4,3*pi/4,100);
a1 = 2;
plot(a1*cos(t),a1*sin(t),'b--')
axis equal

Learn to write code that uses the capabilities of MATLAB in an efficient way.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graphics Performance finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!