Process an Array in Ruby

DSP related issues, mathematics, processing and techniques
Post Reply
OllieMarshall92
Posts: 16
Joined: Wed Oct 26, 2011 12:22 pm

Process an Array in Ruby

Post by OllieMarshall92 »

Hi All,

Basically I want to find the sin([array]) (sine of each value in the array) and then export the array from ruby.

I can find the sine of a float but my code wont do the same to an array. Ruby comes up with an error something like "cant convert array to float".
I think I may need to iterate through the array, processing one at a time but I cant work out how to do that.

Ollie
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Process an Array in Ruby

Post by tulamide »

With "myarr" as the array that contains the data

Code: Select all

na = myarr.map { |v| Math.sin(v) }
"There lies the dog buried" (German saying translated literally)
Lex248
Posts: 33
Joined: Mon Aug 29, 2016 7:44 pm
Location: Russia
Contact:

Re: Process an Array in Ruby

Post by Lex248 »

With RAD2DEG and RAD2GRAD module.
Attachments
sin_array_1.fsm
(486 Bytes) Downloaded 1498 times
sin_array_2.fsm
(534 Bytes) Downloaded 1496 times
Sorry, I bad speak english.
---
My plug-ins http://nalexsoft.blogspot.com/
OllieMarshall92
Posts: 16
Joined: Wed Oct 26, 2011 12:22 pm

Re: Process an Array in Ruby

Post by OllieMarshall92 »

Thanks, both of you.

My input is in degrees, how do I format it so if I put 180 in I get a 0 out? e.g. sin(180) = 0

Ollie
Lex248
Posts: 33
Joined: Mon Aug 29, 2016 7:44 pm
Location: Russia
Contact:

Re: Process an Array in Ruby

Post by Lex248 »

?
Attachments
sin_array.jpg
sin_array.jpg (23.94 KiB) Viewed 21174 times
Sorry, I bad speak english.
---
My plug-ins http://nalexsoft.blogspot.com/
Post Reply