How do I fix my graph?

7 vues (au cours des 30 derniers jours)
123fbyr765
123fbyr765 le 29 Nov 2018
I have a script which creates a few graphs based on calculations carried out. The graph looks very strange however. Once the graph finishes, it appears to go back to the start, so to speak. What can I do to stop this from happening? For example, I want the graph below to stop at ~(260,0) and not go back to ~(0,-900).
  2 commentaires
Bob Thompson
Bob Thompson le 29 Nov 2018
What is causing your dataset to generate the last value?
It would always be an option to simply leave off the last value from the range you are entering as your data set, but this is not a good option as you might lose track of valuable information.
Rena Berman
Rena Berman le 3 Déc 2018

(Answers Dev) Restored edit

Connectez-vous pour commenter.

Réponses (1)

Mark Sherstan
Mark Sherstan le 30 Nov 2018
Modifié(e) : Mark Sherstan le 30 Nov 2018
Try the code below. Esentially I find the first instence when a value is greater than 260 and eliminate from that point to the end in both x and y vectors. You have to be careful with this as you could eliminate some data without meaning to so just make sure you are confident of your cutoff time (e.g. 260 in this case).
x = [0 100 150 200 250 300 0];
y = [0 500 1000 -500 -900 -300 -900];
figure(1); plot(x,y)
idx = find(x>260);
x(idx(1):end) = [];
y(idx(1):end) = [];
figure(2); plot(x,y)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by