How to read the range and corresponding Values

1 次查看(过去 30 天)
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 个评论
Jan
Jan 2015-5-19
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?
Mekala balaji
Mekala balaji 2015-5-20
LB means lower bound, UB means upper bound target mean actual value. 15 is >10 and <20, so, from the table, it belongs to ≤ 20, so my out put should give:315,335,345. I can import the file using xlsread, but after reading the table is in cell format (this is the 1st problem I am facing). Second problem, how search the give number belongs to which range in the given table (columns1), once it search and find the range, then It should give me the corresponding LB,Target, UB (in columns 2,3,4). Kindly help, thank you.

请先登录,再进行评论。

回答(1 个)

Thorsten
Thorsten 2015-5-20
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 个评论
Thorsten
Thorsten 2015-5-22
编辑:Thorsten 2015-5-22
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);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by