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
Process an Array in Ruby
5 posts
• Page 1 of 1
Process an Array in Ruby
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
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: 16
- Joined: Wed Oct 26, 2011 12:22 pm
Re: Process an Array in Ruby
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)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: Process an Array in Ruby
With RAD2DEG and RAD2GRAD module.
- Attachments
-
- sin_array_1.fsm
- (486 Bytes) Downloaded 1397 times
-
- sin_array_2.fsm
- (534 Bytes) Downloaded 1390 times
- Lex248
- Posts: 33
- Joined: Mon Aug 29, 2016 7:44 pm
- Location: Russia
Re: Process an Array in Ruby
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
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: 16
- Joined: Wed Oct 26, 2011 12:22 pm
- Lex248
- Posts: 33
- Joined: Mon Aug 29, 2016 7:44 pm
- Location: Russia
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 38 guests