Yes, But I don't get the condition value( as the output) from the program. I need to map temperature to a condition in the program. how can I do it ?
(Please remember to bottom post. )
After reading in the temperature, you'll have to put some logic in to determine and assign a value to the variable 'condition'.
if (temp < 32)
condition = 'frozen';
elseif (temp < 40)
condition = 'cold';
elseif (temp < 60)
condition = 'warm';
else
condition = 'hot';
endif
Now, if you have a lot of conditions, this will be a rather large and tedious if tree, but it would work. If you're trying to assign a numeric value to a large number of predefined bins, this starts to look like a histogram sorting function. you might be able to use something like 'histc' to do it for you:
will sort the data in 'x' into bins defined by 'binranges'. the output will be 'bincounts' (the number of elements in each bin, probably not of interest) and 'idx' the assignment array telling you which bin each member of 'x' went into. This will be fastest if you build a full array of x and run the histc once, but you should also be able to run it inside a for loop and do one 'x' value at a time. (in that case there is probably a more efficient way to find out where a single number fits in a binrange, but i think it will still work.)
Once you have 'idx', you could maybe map the bins to the condition names you want. (cold, hot, etc.), and store that value in 'condition' to use for your output.