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

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

two things array/ruby related

For general discussion related FlowStone

Re: two things array/ruby related

Postby Nubeat7 » Thu Oct 31, 2013 9:47 pm

RJHollins wrote:not to distract from the OP ... and thanks for the examples TROG ...

but I've been trying to figure out how to change the output of the RUBY box from the proper ARRAY display:
["1", "a", "X"]


to one that is 'clean' .... 1 a X

or

1
a
X

I'm thinking the array is extracted into a string format. But I more familliar using PRIMS and still easily confused with RUBY. [need more practise :lol: ]

Thanks for info!

use stringarray output for the second example and .join(',') for the first one
you also could add .gsub(/\,/,"") to also remove the commas
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: two things array/ruby related

Postby RJHollins » Thu Oct 31, 2013 10:21 pm

.gsub(/\,/,"")


that's the one I keep forgetting about ... :oops:

I actually need to write this on paper to remember it .... and my name :roll:
:lol:
RJHollins
 
Posts: 1571
Joined: Thu Mar 08, 2012 7:58 pm

Re: two things array/ruby related

Postby Nubeat7 » Thu Oct 31, 2013 10:59 pm

or you put this site in your favourites http://ruby-doc.org/core-2.0.0/String.h ... hod-i-gsub
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: two things array/ruby related

Postby billv » Fri Nov 01, 2013 2:11 am

Thanks for the input Trog...

I got first example ok....but the 'nesting' one is killing me all morning... :?

The nesting example data for 3 arrays is structured like this....
["1/2/3", "a/b/c", "X/Y/Z"]

If i input 1 array it is structured like this
["1","2","3"]...

how can i make this method work using "real" inputs...?

and i can't seem to re-define the split....
should i be re-structuring the arrays(join,insert..ect,ect) till I get
a line of text that looks like ["1/2/3", "a/b/c", "X/Y/Z"]...?

Or is another method???

So it's currently...
my_array = ["1/2/3", "a/b/c", "X/Y/Z"]
I want to basicly...
my_array = [@a1, @a2, @a3]
somehow.. :?..and get result..
billv
 
Posts: 1157
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia

Re: two things array/ruby related

Postby billv » Fri Nov 01, 2013 5:00 am

I found the issue i had...

If arrays are not the same size exception is raised....

This works fine ifarrays are same size....

Code: Select all
a = [@a]+[@b]
b = a.transpose
column = b[0]
output 0,column
billv
 
Posts: 1157
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia

Re: two things array/ruby related

Postby tester » Fri Nov 01, 2013 11:52 am

I'm starting to understand less and less from these chats... :D
Module examples are more helpful.

Let me clarify. "Get rows at list of indexes" will look like this I suppose, yes? And rows must not contain commas as a separators in order to work correctly, yes?

BTW, I see that in ruby you can use inputs by @names. What about named outputs?
Attachments
get-rows.fsm
(453 Bytes) Downloaded 806 times
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: two things array/ruby related

Postby tester » Fri Nov 01, 2013 12:10 pm

trogluddite wrote:You're on the right track - but you need an array where each row is itself an array - i.e. nested array structure. So the string for each row will need converting to array form...
Code: Select all
my_array = ["1/2/3", "a/b/c", "X/Y/Z"]

# Convert rows into sub-arrays
nested_array = my_array.map do |row|
  row.split('/')
end

# You now have a nested array...
# [ ["1","2","3"], ["a","b","c"], ["X","Y","Z"] ]

# Now transpose so that columns become rows and vice versa
transposed_array = nested_array.transpose

# transposed array will now be
# [ ["1","a","X"], ["2","b","Y"], ["3","c","Z"] ]

# Get a column
column = transposed_array[0]  #=> ["1", "a", "X"}


I don't get that one. Could you upload it as a module with text connected on input?
Attachments
get-columns.fsm
(674 Bytes) Downloaded 817 times
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: two things array/ruby related

Postby tester » Fri Nov 01, 2013 12:32 pm

Okay, I managed that one, I guess.

Two things that are bothering me:
1) ruby window tend to show errors even if there are no errors (some sort of refreshing issue).
2) I see, that I tend to use names that are reserved for something.
Attachments
get-columns.fsm
(520 Bytes) Downloaded 833 times
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: two things array/ruby related

Postby Nubeat7 » Fri Nov 01, 2013 12:34 pm

tester wrote:
BTW, I see that in ruby you can use inputs by @names. What about named outputs?


Code: Select all
output 'myOutputName', value
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: two things array/ruby related

Postby tester » Fri Nov 01, 2013 12:40 pm

One thing regarding "get column" module. How to fill the array with nils, so that it will not produce an error, if some rows have less values?

Like this:

aaa/111/v/5
bbb/222/b/6
ccc/n

Third row is shorter by 2 items, thus it should end like this:

ccc/n//
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

PreviousNext

Return to General

Who is online

Users browsing this forum: No registered users and 91 guests