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
Generate Array?
6 posts
• Page 1 of 1
Generate Array?
Ok last question for the day.
What's the best way to generate/calculate an array from scratch, in consistent relation to a function from last entry, or the index # ?
so just..
Designating # of x bins...
entering function (ie x=x+3... or x=index ..or x=index*2+3/4^179)
I'm going for pretty big arrays.....
What's the best way to generate/calculate an array from scratch, in consistent relation to a function from last entry, or the index # ?
so just..
Designating # of x bins...
entering function (ie x=x+3... or x=index ..or x=index*2+3/4^179)
I'm going for pretty big arrays.....
-
guyman - Posts: 207
- Joined: Fri Mar 02, 2018 8:27 pm
Re: Generate Array?
Hi Guy ...
not sure exactly what your looking for ... but posted sometime back, TROG had put together a package of modules called 'TROGS TOOLZ'.
In the 'Auto Numbering folder is an AutoFunction Generator that can generate a variety of Arrays and functions.
not sure if this the latest ... but maybe can help:
not sure exactly what your looking for ... but posted sometime back, TROG had put together a package of modules called 'TROGS TOOLZ'.
In the 'Auto Numbering folder is an AutoFunction Generator that can generate a variety of Arrays and functions.
not sure if this the latest ... but maybe can help:
- Attachments
-
- trogz_toolz_v3_1.fsm
- (226.42 KiB) Downloaded 799 times
- RJHollins
- Posts: 1571
- Joined: Thu Mar 08, 2012 7:58 pm
Re: Generate Array?
guyman wrote:What's the best way to generate/calculate an array from scratch, in consistent relation to a function from last entry, or the index # ?
If you know the size of the array beforehand, the best way is to use its built in method #new:
- Code: Select all
my_array = Array.new(20) { |index| index*2+3/4^179 }
## creates an array with 20 entries calculated from the code block {}
if you don't know the size beforehand you have to append to an existing array, for example:
- Code: Select all
my_array = []
index = 0
my_array << index*2+3/4^179
This will make you happy: https://ruby-doc.org/core-1.9.3/index.html
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: Generate Array?
Some options for array creation are:
- Attachments
-
- buildArray3.png (16.95 KiB) Viewed 10396 times
-
- This one will probably upset tula ...
- buildArray2.png (10.82 KiB) Viewed 10396 times
-
- buildArray1.png (16.6 KiB) Viewed 10396 times
-
martinvicanek - Posts: 1328
- Joined: Sat Jun 22, 2013 8:28 pm
Re: Generate Array?
It does, Martin, it does. But for a good reason. It's not "the best" way as asked, it's the worst way, because it's not the Ruby way. A for loop is one of the worst methods, especially when doing large arrays, as the op said.martinvicanek wrote:...
But the other methods impress me! I would never had thought about using ASM, that's amazing!
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: Generate Array?
i like to build an array, as long as you're sure the index number is accurate there really is no drawback unlike javascript or php.
-
wlangfor@uoguelph.ca - Posts: 912
- Joined: Tue Apr 03, 2018 5:50 pm
- Location: North Bay, Ontario, Canada
6 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 66 guests