How do I fix my graph?
6 views (last 30 days)
Show older comments
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 Comments
Bob Thompson
on 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.
Answers (1)
Mark Sherstan
on 30 Nov 2018
Edited: Mark Sherstan
on 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)
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!