How to read the range and corresponding Values
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dear Sirs,
I ahve the following table in excel sheet which contains Range, Lower bound, Target,&Upper bound. I want to specify the range and want to read the corresponding LB, Target & UB by matlab code.
For example if I give Range as 15 (because 15 is >10 ≤20) and my output should be 315,335,&345 or if I specify the range as 0 (zero) and I should get the output as 315,330,345. Or If I give the range as (or 18, or 200)300, my output should be 370,385,390. Kindly some one help me how to read this in matlab. Many many thanks in advance.
Range LB Target UB
0~10 315 330 345
≤ 20 315 335 345
≤ 140 355 370 375
≤ 160 360 375 385
>200 370 385 390
2 comentarios
Jan
el 19 de Mayo de 2015
I do not understand the question. What does LB, Target & UB mean? Where is "given Range as 15" given?
Are you able to import the file using XLSREAD? What did you try so far? Which problems occur?
Respuestas (1)
Thorsten
el 20 de Mayo de 2015
Instead of reading the file, code your table as
T = [10 315 330 345;
20 315 335 345;
140 355 370 375;
160 360 375 385;
200 NaN NaN NaN;
inf 370 385 390];
Then
testval = 15;
row = T(find((T(:,1) > testval) == 1, 1, 'first'), 2:end)
Note that for values between 160 and 200 the table specifies no values, as in your xls-file.
5 comentarios
Thorsten
el 22 de Mayo de 2015
Editada: Thorsten
el 22 de Mayo de 2015
Sorry for not explaining my code; I realized that the code could be simplified as
row = T(find(T(:,1) >= testval, 1), 2:end)
So how does it work? It's helpful to break down the one-liner into its parts:
T(:,1) >= testval
puts logical 1's at all rows that are >= testval, 0's else. For example, for
testval = 140;
you get
>> a = T(:,1) >= testval
a =
0
0
1
1
1
1
Next we want to get index of the first 1. This can be done by
b = find(a, 1)
which is just the short form of
b = find(a, 1, 'first');
Have a look at the help for find to read about this and other variants.
The row we need is the b'th row, and we select the second up to the last column of the matrix T
row = T(b, 2:end);
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!