フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Finding the value of a line when it falls past a certain value on the y axis

1 回表示 (過去 30 日間)
Gareth Pritchard
Gareth Pritchard 2015 年 1 月 21 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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 .

回答 (1 件)

Thorsten
Thorsten 2015 年 1 月 21 日
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

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by