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

Process an Array in Ruby

DSP related issues, mathematics, processing and techniques

Process an Array in Ruby

Postby OllieMarshall92 » Tue Oct 18, 2016 8:26 am

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
OllieMarshall92
 
Posts: 12
Joined: Wed Oct 26, 2011 12:22 pm

Re: Process an Array in Ruby

Postby tulamide » Tue Oct 18, 2016 9:00 am

With "myarr" as the array that contains the data
Code: Select all
na = myarr.map { |v| Math.sin(v) }
tulamide
 
Posts: 2108
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Process an Array in Ruby

Postby Lex248 » Tue Oct 18, 2016 9:56 am

With RAD2DEG and RAD2GRAD module.
Attachments
sin_array_1.fsm
(486 Bytes) Downloaded 413 times
sin_array_2.fsm
(534 Bytes) Downloaded 403 times
Sorry, I bad speak english.
---
My plug-ins http://nalexsoft.blogspot.com/
Lex248
 
Posts: 33
Joined: Mon Aug 29, 2016 7:44 pm
Location: Russia

Re: Process an Array in Ruby

Postby OllieMarshall92 » Tue Oct 18, 2016 10:26 am

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
OllieMarshall92
 
Posts: 12
Joined: Wed Oct 26, 2011 12:22 pm

Re: Process an Array in Ruby

Postby Lex248 » Tue Oct 18, 2016 12:42 pm

?
Attachments
sin_array.jpg
sin_array.jpg (23.94 KiB) Viewed 8509 times
Sorry, I bad speak english.
---
My plug-ins http://nalexsoft.blogspot.com/
Lex248
 
Posts: 33
Joined: Mon Aug 29, 2016 7:44 pm
Location: Russia


Return to DSP

Who is online

Users browsing this forum: Majestic-12 [Bot] and 6 guests

cron