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

transpose rows into columns

For general discussion related FlowStone

transpose rows into columns

Postby tester » Fri Jan 22, 2016 11:05 pm

1) How to display whole transposed (rows into colums) matrix?
1a) How to display (as int) amount of columns after transpose?

2) How to approach to this, if input contains rows with different element sizes?
Attachments
transpose.fsm
(466 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: transpose rows into columns

Postby KG_is_back » Sat Jan 23, 2016 12:46 am

Unfortunately flowstone ruby doesn't support standard ruby library, which contains Matrix class. Here is the solution - modified version of what you have in your schematic. It works also with arrays, which have different lengths of lines, or even missing values.

Code: Select all

def transpose(matrix)
   #find longest line( to determine number of raws)
   ln=matrix.max{|line1,line2| line1.size<=>line2.size}.size
   trn=Array.new(ln){|i|
   matrix.map{|line| line[i]}
   }
   return trn
end

asd1 = @in1.map do |row|
row.split('^')
end
watch "old",asd1
asd2 = transpose(asd1)
watch "new",asd2
output 0, asd2[@in2]
output 1, asd2.map{|line| line.join("^")}


to find the length of the longest line (the number of columns) use:
Code: Select all
matrix.max{|line1,line2| line1.size<=>line2.size}.size
KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: transpose rows into columns

Postby tester » Sat Jan 23, 2016 10:30 am

Thanks KG!
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


Return to General

Who is online

Users browsing this forum: Google [Bot] and 118 guests

cron