Filter löschen
Filter löschen

Input data, round down, loop variable

1 Ansicht (letzte 30 Tage)
GH
GH am 27 Mai 2020
Kommentiert: GH am 27 Mai 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.

Akzeptierte Antwort

Tommy
Tommy am 27 Mai 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 Kommentar
GH
GH am 27 Mai 2020
Thank you very much! Exactly what I needed!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by