Azzera filtri
Azzera filtri

how to plot connected points ?

1 visualizzazione (ultimi 30 giorni)
RuiQi
RuiQi il 3 Mar 2017
Risposto: Image Analyst il 3 Mar 2017
How do i plot(x,y) such that the points are connected to each other instead of from the origin ?

Risposta accettata

Star Strider
Star Strider il 3 Mar 2017
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 Commenti
RuiQi
RuiQi il 3 Mar 2017
Argh forgot about that 'trick' ! Thanks so much !
Star Strider
Star Strider il 3 Mar 2017
My pleasure!

Accedi per commentare.

Più risposte (1)

Image Analyst
Image Analyst il 3 Mar 2017
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;

Categorie

Scopri di più su Graphics Performance in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by