help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Printing the values ​​on the .csv file


From: Nicholas Jankowski
Subject: Re: Printing the values ​​on the .csv file
Date: Mon, 8 Jun 2020 16:39:58 -0400

On Mon, Jun 8, 2020 at 4:16 PM Ganesh Kini <ganeshrkini19@gmail.com> wrote:
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:

[bincounts, idx ]= histc(x,binranges)  

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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]