Clear Filters
Clear Filters

Please tell me how to erase meaningless lines from graphs!

2 views (last 30 days)
In the graph above, I want to erase the line that crosses pi at -pi, how can I do it?
I wasn't there originally... It's a simple question, but I can't solve it.
plot(data(:,1),data(:,2))
xlim([-pi pi])
xticks(-pi:pi/2:pi)
xticklabels({'-\pi','-\pi/2','0','\pi/2','\pi'})
pbaspect([ 1 1 1])
grid on
xlabel('rad')
ylabel('mm')

Accepted Answer

Dyuman Joshi
Dyuman Joshi on 6 Sep 2022
Edited: Dyuman Joshi on 6 Sep 2022
There is repetition in your data, 1st and Last row are the same.
%plot upto 2nd last row
plot(data(1:end-1,1),data(1:end-1,2))
xlim([-pi pi])
xticks(-pi:pi/2:pi)
xticklabels({'-\pi','-\pi/2','0','\pi/2','\pi'})
pbaspect([ 1 1 1])
grid on
xlabel('rad')
ylabel('mm')

More Answers (1)

Star Strider
Star Strider on 6 Sep 2022
There is no need to discard any data. Just use sortrows to sort them —
LD = load(websave('data','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1117765/data.mat'));
data = LD.u;
data = sortrows(data,1);
plot(data(:,1),data(:,2))
xlim([-pi pi])
xticks(-pi:pi/2:pi)
xticklabels({'-\pi','-\pi/2','0','\pi/2','\pi'})
pbaspect([ 1 1 1])
grid on
xlabel('rad')
ylabel('mm')
The ‘wrapped’ lines are almost always solved by sorting.
.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!