Input data, round down, loop variable

1 view (last 30 days)
GH
GH on 27 May 2020
Commented: GH on 27 May 2020
Hi everyone, I have lots of data in an excel file with 59 rows and 4 colums, every row's data belong together(let's say I have 'x', 'z', 'R', 'y'). I have two problems:
a) One of the variable (let's say 'y') should be an input value by the user, then the program should find in which domain (which are the those two values from the y column in between this input takes place) then choose the lower one and use that in the equation.
b) After the matlab have chosen the proper value, the loop should use its row's data (x,y,z,R) in a 4 variable equation to get the result.

Accepted Answer

Tommy
Tommy on 27 May 2020
How does this work? (I'm assuming T.y is monotonically increasing)
% example table:
x = randi(10,59,1);
y = cumsum(rand(59,1));
z = randi([10 20],59,1);
R = randi([2 3],59,1);
T = table(x, y, z, R);
% example user input:
yin = range(T.y)*rand + min(T.y);
%---------------------------------
% location of row of interest:
idx = find(yin > T.y, 1, 'last');
% row of interest:
vars = T{idx,:};
% vars is a 1x4 array containing the x, y, z, and R to use in your equation
  1 Comment
GH
GH on 27 May 2020
Thank you very much! Exactly what I needed!

Sign in to comment.

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!