How do i plot(x,y) such that the points are connected to each other instead of from the origin ?

 채택된 답변

Star Strider
Star Strider 2017년 3월 3일

1 개 추천

I was able to reproduce your problem:
x = [zeros(1,10); 1:10]; % Simulate Data
x = x(:); % Simulate Data
y = [zeros(1, 10); rand(1, 10)]; % Simulate Data
y = y(:); % Simulate Data
figure(1)
plot(x, y) % Reproduces Problem
figure(2)
plot(x(x ~= 0), y(y ~= 0)) % Fixes Problem
The solution is to take the non-zero values in both the x and y vectors, as I do in figure(2). That should give you the plot you want.

댓글 수: 2

RuiQi
RuiQi 2017년 3월 3일
Argh forgot about that 'trick' ! Thanks so much !
Star Strider
Star Strider 2017년 3월 3일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2017년 3월 3일

0 개 추천

If you want them going monotonically from left to right, then you can sort them.
[newX, sortOrder] = sort(x); % Sort x ascending.
newY = y(sortOrder); % Sort y in exactly the same order.
plot(newX, newY, 'b-*');
grid on;

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

질문:

2017년 3월 3일

답변:

2017년 3월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by