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

Generate Array?

For general discussion related FlowStone

Generate Array?

Postby guyman » Sat Nov 16, 2019 11:11 pm

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.....
User avatar
guyman
 
Posts: 173
Joined: Fri Mar 02, 2018 8:27 pm

Re: Generate Array?

Postby RJHollins » Sun Nov 17, 2019 12:33 am

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:
Attachments
trogz_toolz_v3_1.fsm
(226.42 KiB) Downloaded 121 times
RJHollins
 
Posts: 1411
Joined: Thu Mar 08, 2012 7:58 pm

Re: Generate Array?

Postby tulamide » Sun Nov 17, 2019 1:14 am

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
If you feel like gifting: https://paypal.me/tulamide
tulamide
 
Posts: 2196
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Generate Array?

Postby martinvicanek » Sun Nov 17, 2019 3:55 pm

Some options for array creation are: :mrgreen:
Attachments
buildArray3.png
buildArray3.png (16.95 KiB) Viewed 1757 times
buildArray2.png
This one will probably upset tula ...
buildArray2.png (10.82 KiB) Viewed 1757 times
buildArray1.png
buildArray1.png (16.6 KiB) Viewed 1757 times
User avatar
martinvicanek
 
Posts: 1080
Joined: Sat Jun 22, 2013 8:28 pm

Re: Generate Array?

Postby tulamide » Sun Nov 17, 2019 4:35 pm

martinvicanek wrote:...
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.

But the other methods impress me! I would never had thought about using ASM, that's amazing!
If you feel like gifting: https://paypal.me/tulamide
tulamide
 
Posts: 2196
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Generate Array?

Postby wlangfor@uoguelph.ca » Fri Nov 22, 2019 7:58 pm

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.
User avatar
wlangfor@uoguelph.ca
 
Posts: 800
Joined: Tue Apr 03, 2018 5:50 pm
Location: North Bay, Ontario, Canada


Return to General

Who is online

Users browsing this forum: k brown and 11 guests