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)
min/max filtering (array)
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).
Feel free to donate. Thank you for your contribution.
Re: min/max filtering (array)
http://www.dsprobotics.com/support/viewtopic.php?f=3&t=1760#p8243
It's got a min/max for array in there....
Headquartershttps://www.bvmusicsydneyaustralia.com/
Spotifyhttps://open.spotify.com/artist/7JO8QM40mVmHb7pAwKPJi0
Donatationhttps://www.paypal.com/donate/?hosted_button_id=HEUR8R7K8GZ4L
Re: min/max filtering (array)
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]
Feel free to donate. Thank you for your contribution.
Re: min/max filtering (array)
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}
endwould 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
endand u can use it like this :
Code: Select all
output @yourarray.limit(minVal,maxVal)too!
Re: min/max filtering (array)
http://ruby-doc.org/core-2.0.0/Array.html
Re: min/max filtering (array)
Gives exact same output as standard green min/max...
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
endHeadquartershttps://www.bvmusicsydneyaustralia.com/
Spotifyhttps://open.spotify.com/artist/7JO8QM40mVmHb7pAwKPJi0
Donatationhttps://www.paypal.com/donate/?hosted_button_id=HEUR8R7K8GZ4L
Re: min/max filtering (array)
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
Headquartershttps://www.bvmusicsydneyaustralia.com/
Spotifyhttps://open.spotify.com/artist/7JO8QM40mVmHb7pAwKPJi0
Donatationhttps://www.paypal.com/donate/?hosted_button_id=HEUR8R7K8GZ4L
Re: min/max filtering (array)
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"
Re: min/max filtering (array)
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 }).compactRe: min/max filtering (array)
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
endI 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
endHeadquartershttps://www.bvmusicsydneyaustralia.com/
Spotifyhttps://open.spotify.com/artist/7JO8QM40mVmHb7pAwKPJi0
Donatationhttps://www.paypal.com/donate/?hosted_button_id=HEUR8R7K8GZ4L