Hi,
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?

2 comentarios

Torsten
Torsten el 17 de Abr. de 2022
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.
Better work with the data, not with the graphics.
Sokratis Panagiotidis
Sokratis Panagiotidis el 19 de Abr. de 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.

Iniciar sesión para comentar.

 Respuesta aceptada

Tala
Tala el 17 de Abr. de 2022
Editada: Tala el 18 de Abr. de 2022

0 votos

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.
newblue=blue;
newblue(id1:end)=yellow;
newblue(id2:end)=red;

7 comentarios

Sokratis Panagiotidis
Sokratis Panagiotidis el 18 de Abr. de 2022
I tried your method but it gets the error, that the vectors are not of the same length, which is weird since this method should actually cut them into the same length?
Tala
Tala el 18 de Abr. de 2022
Please attach your arrays, I will take a look
Sokratis Panagiotidis
Sokratis Panagiotidis el 19 de Abr. de 2022
Editada: Sokratis Panagiotidis el 27 de Abr. de 2022
I couldn't do it here since it exceeded the 5 MB limit so I sent the WeTransfer link for you to download @Tala
I managed to do it manually, but my goal is to find a way to make it automated, so that I can use different vectors or even more or less than 3 like here.
(x1,y1) is the blue one, (x2,y2) is the red one, (y3,x3) is the yellow one in the middle.
Tala
Tala el 19 de Abr. de 2022
You got a lot of Nans in your data set. You could simily eliminat ethem but then you would have a big jump from 19.4636 to 63.9776 in Y1. You need to make a decision on what do you want to "sacrifice" and clean up your data before plotting
@Tala The plan is to look into this topic later on when I have managed to further develop the code I am currently working on.
My plan is to go through the vector itself and eliminate all values until the very last NaN, so that the next value of 63.9776 is gonna be the first value of y1 (and also I am gonna eliinate the values of x1 in the same frame or rather not take them into consideration.
Here is what I made manually (the goal is to have it done automatically with multiple different graphs rather than having to do it by hand):
I define the space between the blue and the yellow graph as Delta
% Delta = x1(x3(1)) -x3(1)
% Let's say yellow(1), not taking NaN's into consideration,
Delta = x1(x3(1)) - x3(1);
and then I added it into x3, making it
xx3 = x3 + Delta;
but now I gotta do that manually with the red graph (x2, y2).
Would you say there's a way to do so or should I take care of the NaN's first? What's your take on this?
Tala
Tala el 19 de Abr. de 2022
Editada: Tala el 19 de Abr. de 2022
You basically need to move your curves along th X axis; in other words you need to plot(x+dx,y). To define dx you need to clean up your data. in the code below, I removed all nans and chose the last value (because there is no "jump") as the ref point and moved all the curves. As you see you have a better match towards the tail of the curves because the ref point is the last point.
You could clean up your data and get rid of the jump in the start of blue curve and use the first element as your ref point, then you get a better match towards the beginning. In that case just change "end" to "1"
you could take the avarage of first and last, or even interpolate over a unique x aeeay, and move each point individually using this method
X1=data.x1;Y1=data.y1;X2=data.x2;Y2=data.y2;X3=data.x3;Y3=data.y3;
% removing nans
TF = find(~isnan(Y1));
Y1N=Y1(TF);
X1N=X1(TF);
TF = find(~isnan(Y2));
Y2N=Y2(TF);
X2N=X2(TF);
TF = find(~isnan(Y3));
Y3N=Y3(TF);
X3N=X3(TF);
% now plot arrays with no nans
plot(X1N,Y1N)
hold on
plot(X2N,Y2N)
plot(X3N,Y3N)
% defining dx and moving your plots
d13=(X1N(end)-X3N(end));
plot(X3N+d13,Y3N);
d12=(X1N(end)-X2N(end));
plot(X2N+d12,Y2N);
Sokratis Panagiotidis
Sokratis Panagiotidis el 23 de Abr. de 2022
Hello,
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.

Iniciar sesión para comentar.

Más respuestas (1)

Matt J
Matt J el 17 de Abr. de 2022
Editada: Matt J el 17 de Abr. de 2022

0 votos

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:
x1_shifted=x1-mean(x1)+mean(interp1(y0,x0,y1));
x2_shifted=x2-mean(x2)+mean(interp1(y0,x0,y2));

Categorías

Más información sobre Graphics Performance en Centro de ayuda y File Exchange.

Preguntada:

el 17 de Abr. de 2022

Editada:

el 27 de Abr. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by