Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Finding the value of a line when it falls past a certain value on the y axis
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
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
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!