Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Finding the value of a line when it falls past a certain value on the y axis
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have an array (in this instance called Jan) of 16 values filled with random numbers between 0 and 1, where no value is larger than the one coming before it, resulting in an almost straight line from 1 to 0.
I have another array, length which is simply given by [0:200:3000]
What I want to do is to find out at which value of length that the value of Jan falls at precisely 0.7. The line will only pass through this value once, so one value out is all I'm expecting. I'm guessing there is a way to solve it using interpolation, but I'm not very familiar with using it, and I'm also confident there has to be a quick way to solve this that I'm missing.
Any help solving this would be gratefully accepted .
0 commentaires
Réponses (1)
Thorsten
le 21 Jan 2015
First, don't use "length" as a variable, it's a function in Matlab. I used L instead.
In general there will be no value in L with the 200 spacing that corresponds precisely to 0.7. In fact, only if 0.7 is by chance one of the 16 random number you will find such a value. Else, you have to interpolate:
jan = sort(rand(1,16), 'descend');
val = 0.7;
L = [0:200:3000];
i1 = find(jan >= val, 1, 'last');
i2 = find(jan <= val, 1, 'first');
if i1 == i2
l = L(i1);
else % interpolate
% slope
m = (jan(i2) - jan(i1))/(L(i2) - L(i1));
% y = m*x + y0; y== val, y0 = L(i1); solve for x and add xoffset L(i1)
l = (val - jan(i1))/m + L(i1);
end
0 commentaires
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!