필터 지우기
필터 지우기

Please tell me how to erase meaningless lines from graphs!

조회 수: 2 (최근 30일)
장훈 정
장훈 정 2022년 9월 6일
답변: Star Strider 2022년 9월 6일
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')

채택된 답변

Dyuman Joshi
Dyuman Joshi 2022년 9월 6일
편집: Dyuman Joshi 2022년 9월 6일
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')

추가 답변 (1개)

Star Strider
Star Strider 2022년 9월 6일
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.
.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by