Finding the Y value corresponding to X value in a parametric plot

how do i find the value of Y when X= 1360 for every loop? X and Y gives a matrix. s is a random number for each loop
smax=0.4;
smin=0.1;
S=smin+rand(1,n)*(smax-smin);
S_cumulative=cumsum(S);
n= 3200;
R=200.04;
V=30;
v=20000;
i=1;
while i<n
t= linspace (0,50,100000);
X=R*sind((v*t/(R))+(V*(t))+S_cumulative(i);
Y=-R*cosd((v*t/R));
end
i=i+1;

2 comentarios

KL
KL el 5 de Oct. de 2017
Editada: KL el 5 de Oct. de 2017
Hi Joseph, Can you describe what you're trying to achieve this code?
Joseph Lee
Joseph Lee el 5 de Oct. de 2017
Editada: Joseph Lee el 5 de Oct. de 2017
this plots 3200 parametric curves and im trying to find the minimum Y values among all the curves for X range {1360,1400}, eg. for position X=1360, i want to find the lowest Y value for that point given by all the curves. using find(X==1360) does not work. I can solve it on paper by finding t, time then substituting into Y equation but i cant put this into the code.

Iniciar sesión para comentar.

 Respuesta aceptada

KL
KL el 5 de Oct. de 2017
Editada: KL el 5 de Oct. de 2017
If all your curves have the same timestep and same number of measurements why not put them all together in a matrix and then find the minimum? For example,
allY = rand(10,4); %say, you have 4 curves with 10 values (random data in this example)
X = (1:10)';
data_summary = [X allY] %put them together
intvl = 3:6; %in your case 1360 to 1400
minVals = min(data_summary(intvl,2:end))

7 comentarios

Joseph Lee
Joseph Lee el 6 de Oct. de 2017
Editada: Joseph Lee el 6 de Oct. de 2017
i tried storing the Y values but Y is a matrix with 100000 columns for every loop because of the linspace and it says 'variable appears to change size every loop' Storing a matrix inside a matrix does not seem possible. what im attempting now is In loop:
j= 1360;
while j<1400
idx= find(round(X)== j);
YY(j,:)=min(Y(idx));
end
j=j+0.1;
i found out why find does not work, its because Y values are not exact and integers, they are a matrix of many decimal places. Still figuring out how to store YY for every loop and it takes a very long time, is there an alternative parametric equation coding method? If i decrease the linspace values, the values would not be accurate. Just ran for over an hour for a single i loop and is still running.
Hi Joseph, I'm not able to understand what you're trying to do. Why on't you create a minimal example with a smaller size. let's say 100 columns?
P.S: "Storing a matrix inside a matrix does not seem possible" ... This is exactly why we have cell arrays in MATLAB.
Joseph Lee
Joseph Lee el 9 de Oct. de 2017
Editada: Joseph Lee el 9 de Oct. de 2017
it will affect the accuracy and the plot would be zig zagged instead of a curve, it took forever to run just a single matrix for n=1
No, such minimal example is just for us to recreate your problem and suggest a solution which you could apply in your case. Do you get the idea? We don't even need your computations. Take the example I provided you in my answer.
allY = rand(10,4); %say, you have 4 curves with 10 values (random data in this example)
X = (1:10)';
data_summary = [X allY] %put them together
intvl = 3:6; %in your case 1360 to 1400
minVals = min(data_summary(intvl,2:end))
Here I create a dummy data for Y and X and then put them all together in one matrix and find the minimum value in a certain interval.
Joseph Lee
Joseph Lee el 11 de Oct. de 2017
Editada: Joseph Lee el 11 de Oct. de 2017
I tried your example but it doesnt work as intended, you are finding the minimum y value for each curve instead of finding minimum y value among the curves and X=1 does not mean y is located in first column since X is a sin function.
I tried cell array to store all the X and Y values now its about finding the minimum Y, I changed the X to range to find from X = 8 to 24, which I wonder how i can put them together... n= 3169 the total number of loops/ curves i is an increment of +1 from 1 to 3169
M = cell(n, 1) ;
N = cell(n, 1) ;
%for each loop
N{i}=X;
M{i}=Y;
As far as I have understood, every column of the Y matrix is a curve and they are somehow associated with X along the row. So when I say find minimum value of Y when X = 6 (for example), we are trying to find the minimum along the row 6 across all columns (hence along all curves).
You're saying there are 100000 values of y for each iteration (or curve), well that means 100000 x, right? How about storing it vertically?
X Y1
1 0.4
2 0.2
... ...
100000 0.34
and then concatenate it horizontally for the next iteration,
X Y1 Y2
1 0.4 0.8
2 0.2 0.4
... ... ...
100000 0.34 0.1
So, this how I could understand the problem from your descriptions. This is why we insist on creating a minimal example with a sample code.
This worked, thanks for tip on arrays. Im looking for a way to find minimum for the 1st column of each cell, comparing the 1st,2nd columns and so on to get the minimum.
M = cell(n, 1) ;
j=8;
N=1;
while j<=24
while N<=160
idx=find(abs(X-j)<0.01);
Ymin(N,:)=min(Y(idx));
j=j+0.1;
N=N+1;
end
end
M{i}=Ymin;

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Preguntada:

el 5 de Oct. de 2017

Comentada:

el 12 de Oct. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by