How to plot circular phase in planar axis without lines going from ymin to ymax when data goes from -pi to pi?

8 views (last 30 days)
I am try to plot a phase response curve on a planar axis. This means when the response is near it may shift directly to π because they are mathematically equivalent in this case. When I plot this on a typical axis, it can lead to a lot of big vertical lines crossing from ymin to ymax which make the appearance of a big shift in the data where none exists. I would like to get rid of this while still plotting using a line as the data is sampled highly enough that continuity should be reasonably inferred. See an image of the problem below.
Instead what I am looking for is to remove the abrupt cross graph lines that occur when values around pi and -pi cross over. Something like this figure which I've drawn over a scatter plot of the same figure.
Is there anyway to have a continuous line that stops during abrupt transitions?
Edited: Edit to add the goal plot to the main text, in answer to star strider's response!

Accepted Answer

Star Strider
Star Strider on 25 Sep 2023
I am not certain what result you want. The phase plots appear to be radian measure and otherwise relatively continuous, so see if the unwrap function will do what you want.
  4 Comments
Keith Doelling
Keith Doelling on 25 Sep 2023
Thank you! Solution 1 has the unfortunate side effect of deleting the first data point either before or after the jump, but it's probably the most straightforward answer. Otherwise, I would have to insert nans between the two points for both x and y, and if y has multiple columns (it does), then it gets weirder and weirder. Thanks for your input!
Star Strider
Star Strider on 25 Sep 2023
As always, my pleasure!
The alternative approach that involves plotting the segments still requires NaN entries to avoid plotting the connecting llines, although if I remember correctly, it previously didn’t require them —
x = linspace(0, 2*pi, 250);
y = rem(5*sin(x) - x/2, pi);
figure
plot(x, y)
idx = find(diff(sign(abs(y) - pi*0.955)));
idx = [1 idx numel(x)]; % This Requires 'idx' To Have An Even Number Of Elements.
idxm = reshape(idx, 2, [])
idxm = 2×6
1 32 87 136 165 220 30 85 135 163 218 250
figure
hold on
for k = 1:size(idxm,2)
idxrng = idxm(1,k) : idxm(2,k);
plot([NaN x(idxrng(2:end))], [NaN y(idxrng(2:end))])
end
hold off
.

Sign in to comment.

More Answers (0)

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!