Please tell me how to erase meaningless lines from graphs!

1 visualizzazione (ultimi 30 giorni)
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')

Risposta accettata

Dyuman Joshi
Dyuman Joshi il 6 Set 2022
Modificato: Dyuman Joshi il 6 Set 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')

Più risposte (1)

Star Strider
Star Strider il 6 Set 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.
.

Categorie

Scopri di più su Discrete Data Plots in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by