Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

min/max filtering (array)

For general discussion related FlowStone

min/max filtering (array)

Postby tester » Sat Nov 09, 2013 12:22 am

One of previous topics created another one.

Within array, how to filter values within min/max range?

Let say that min=0, max=200
then from values: -1,2,40,100,400
only these in min/max range are on output.

I guess this can be done by filtering all above and below, or by pushing through all within minmax range.

I'm reading these ruby docs, but can't understand how to get it (I even have no idea whether I'm reading the right thing).
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: min/max filtering (array)

Postby billv » Sat Nov 09, 2013 12:39 am

You can try the nubeat7 class array thing....
http://www.dsprobotics.com/support/viewtopic.php?f=3&t=1760#p8243
It's got a min/max for array in there....
billv
 
Posts: 1157
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia

Re: min/max filtering (array)

Postby tester » Sat Nov 09, 2013 1:08 am

I guess you mean this part
Code: Select all
   def limit (minVal,maxVal)
     return self.map{|item|[[item,minVal].max,maxVal].min}
   end

I'm not sure how to put it to work (ins/outs as usual]
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: min/max filtering (array)

Postby Nubeat7 » Sat Nov 09, 2013 1:37 am

just put the module inside your schematic ( before any other ruby module)
and you can use it like
Code: Select all
output @yourarray.limit(minVal,maxVal)


if you dont want to use the methode expansion module you have to rewrite the methode from a class methode (the stuff with self) to a "normal" methode where self would be your array:

Code: Select all
def limit (minVal,maxVal)
     return self.map{|item|[[item,minVal].max,maxVal].min}
   end

would be
Code: Select all
output @yourArray.map{|item|[[item,minVal].max,maxVal].min}


to use it like the class methode without putting the expansion module inside the schematic you also could declare the methode in your ruby module like:
Code: Select all
class Array
def limit (minVal,maxVal)
     return self.map{|item|[[item,minVal].max,maxVal].min}
   end
end


and u can use it like this :
Code: Select all
output @yourarray.limit(minVal,maxVal)

too!
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: min/max filtering (array)

Postby Nubeat7 » Sat Nov 09, 2013 1:51 am

but sorry i didnt read the first post well, just answered to billvs idea.. the above methode describes how to set all values inside an array to min /max values (limits the values!) to show just the values which are in a given range you need a different methode... but sorry too tired atm.. have to work tomorrow but search keep_if here:
http://ruby-doc.org/core-2.0.0/Array.html
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: min/max filtering (array)

Postby billv » Sat Nov 09, 2013 3:59 am

Got it tester....took longer than expected.. :?
Gives exact same output as standard green min/max... :D
Float array input and output...
Code: Select all
def event i,v
  if i == 0 then
  data=[]
  x=0
  minVal = 0.5
  maxVal = 1
  a = maxVal - minVal
  @list.length.times do |x|   
  data[x] = @list.map{ |x| x.to_f * a + minVal }
     x += 1     
end
   output 0,data[0]
    watch  data
end
end
billv
 
Posts: 1157
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia

Re: min/max filtering (array)

Postby billv » Sat Nov 09, 2013 5:20 am

This is a single float version...
Code: Select all
def event i,v
  if i == 0 then
    minVal = -0.5
    maxVal = 0.5
     a =  maxVal - minVal
     b =  @txt * a
     c =  b + minVal
               
    output 0,c
end
end


@nubeat7
Did have a lot of trouble using
Code: Select all
.map{|item|item*maxVal-minVal+minVal}

dosn't seem to happen with the "maxVal-minVal" where it is...
if you follow the flow of standard green min/max..
the "maxVal-minVal" dosn't belong inside main calculation...so it sort of makes sense
billv
 
Posts: 1157
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia

Re: min/max filtering (array)

Postby Nubeat7 » Sat Nov 09, 2013 9:12 am

@tester
this should do it:
Code: Select all
output @yourarray.keep_if{|x|x>minValue && x<maxValue}

billv wrote:@nubeat7
Did have a lot of trouble using
CODE: SELECT ALL
.map{|item|item*maxVal-minVal+minVal}

dosn't seem to happen with the "maxVal-minVal" where it is...
if you follow the flow of standard green min/max..
the "maxVal-minVal" dosn't belong inside main calculation...so it sort of makes sense


what you are trying to do here is scaling the values to min max range.. look inside my expansion module the methode calls "scale_values"
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: min/max filtering (array)

Postby Tronic » Sat Nov 09, 2013 9:45 am

just one line method
Code: Select all
# range method (n..n) === N

val_to_test_in_range = @in;
val_if_in_range = @in ;
val_if_not_in_range = 0.0 ;

min = 0.0 ;
max = 0.5 ;

is_val_in_range = (min..max) === val_to_test_in_range ? val_if_in_range : val_if_not_in_range ;

... with array
Code: Select all
array = [-1,0.0,90,50,100,150,200]

min = 0.0 ;
max = 100 ;

(array.map {|v| (min..max) === v ? v : nil }).compact
Tronic
 
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: min/max filtering (array)

Postby billv » Sat Nov 09, 2013 10:24 am

Nubeat7 wrote:what you are trying to do here is scaling the values to min max range.. look inside my expansion module the methode calls "scale_values"

I actually posted the limiter fix for tester from your fsm,
but for some reason i deleted it and changed it to scale..
While the limiter works fine...
Code: Select all
def event i,v
  if i == 0 then
    minVal = 0
    maxVal = 1
   a = @txt.map{|item|[[item,minVal].max,maxVal].min}
   output 0,a
  end
end


I still can't get a result from this...
Code: Select all
def event i,v
  if i == 0 then
    minVal = 0.5
    maxVal = 1
   a = @txt.map{|item|item*maxVal-minVal+minVal}
   output 0,a
  end
end
billv
 
Posts: 1157
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia

Next

Return to General

Who is online

Users browsing this forum: No registered users and 61 guests