How to determine which range a number is in and then report a value from a table

2 次查看(过去 30 天)
I'm looking for help and advice on a difficult problem, at least difficult for a Matlab novice like me.
I have a single column of temperature values in one variable, and a table of other values. This table consists of temperatures of -30 to 50 increasing in steps of 10 as the first row. In the first column I have name strings that identify different sensors. The remaining table is composed of numbers that are sensitivities.
I want to read the temperature, determine where the temperature is between two values in the table in row 1, then along with the sensor ID, obtain a value for the sensitivity which will feed into subsequent calculations.
For example.
S_temp = [{4.5 -4.2 7 9.6 -9.5}]' % some random values of temperature
labels = [{'Temp' 's1' 's2' 's3' 's4'}]';
table = [{-10 -8 -6 -4 -2 0 2 4 6 8 10};{1 2 3 7 4 6 8 9 3 1 6};{0.1 0.2 0.8 1 5 10 9 8 4 7 7};{1 2 1.8 2 10 4 8 8 2 4 6};{0.1 0.2 6.8 12 11 14 8 6 2 4 6}];
table = [labels,table]; % to construct my query table
Going down the list of temperatures, the first value is 4.5. In the table its between 4 and 6. Lets also say I want to look along Row s2. Taking the upper value of the identified range (i.e. 6) my target value within the table is 4. The second temperature is -4.2, target value in the table (for s2) is 0.8...and so on down the list of temperatures.
Any advice and help on this would be gratefully received.

采纳的回答

Steven Lord
Steven Lord 2015-9-18
Take a look at the DISCRETIZE function. You may also want to store your data in a TABLE as then you can use the row indices from DISCRETIZE with the variable (column) names to retrieve data from the table.
  1 个评论
Wah On Ho
Wah On Ho 2015-9-18
Thank you. I've just taken a quick look at the function and it looks promising. I didn't think about the problem in terms of creating bins with the ranges as the bin intervals.

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by