Moving graph along x-axis

34 views (last 30 days)
Sokratis Panagiotidis
Sokratis Panagiotidis on 17 Apr 2022
I am trying to plot 3 different vectors that showcase the same function but with different starting points from the y-axis.
Now what I wanna do is move the yellow and the red graph so they overlap with the blue one, to see wether my determined data actually is correct. I have another picture here to further show what exactly I mean:
Now I have tried to do something similar but with the y-axis but unfortunately I couldn't make it work.
What would be a clever way to move the graphs without having to change the values of the vectors?
Sokratis Panagiotidis
Sokratis Panagiotidis on 19 Apr 2022
@Torsten I mean yeah that's exactly what I am trying to do. I only used the graphics to better show what I was talking about.

Sign in to comment.

Accepted Answer

Tala on 17 Apr 2022
Edited: Tala on 18 Apr 2022
I would subtitute the other 2 array in the main one and plot that. something lik ethis:
id1 = find(blue==yellow(1)); % the index on the blue curve that matches the first value of yellow
id2 = find(blue==red(1)); % the index on the blue curve that matches the first value of red
now use the id values to create a new array. newblue contain the values from blue, yellow and red curves, and you can just plot newblue.
Sokratis Panagiotidis
Sokratis Panagiotidis on 23 Apr 2022
You method worked thanks a lot!
But here's one thing I'd like to say:
Your method removes all NaN's, but let's say I have a vector
[0 0 NaN 0 0 NaN NaN 0 NaN 0 0 NaN 1 0 0 0 0 0]
it would give me
[0 0 0 0 0 0 0 1 0 0 0 0 0] (I put in a 1 to make it more clear).
Now that itself is already great but I believe the values before the last NaN are useless, as I cannot work with them if I remove something after it, so Imma go and look into a method to first remove everything up to the last NaN, so that I get
[1 0 0 0 0 0] and have therefore a much shorter vector but at least I won't have gaps in between two values, but I'll also try to find a way to adapt it into a automated loop, so that it works for a N-amount of vectors and it would additionally find the longer vector (here blue) and valculate dx for the rest rather than having to do it for every sinle one manually (as I will sometimes be working with up to 20 vectors or even more).
Still tanks a lot! I marked your answer as helpful.

Sign in to comment.

More Answers (1)

Matt J
Matt J on 17 Apr 2022
Edited: Matt J on 17 Apr 2022
Let's call your 3 data sets (x0,y0), (x1,y1), (x2,y2) where (x0,y0) are your target data points. Then I might try something like this:


Find more on Graphics Performance 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!

Translated by