How to retrieve a column array from a 2-D array?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: How to retrieve a column array from a 2-D array?

Post by MaxV » Thu Jun 19, 2014 2:55 pm

I use this:

on visualizzamatrix mat
#this visualize a bidimensional matrix like A x B
#rows
put the keys of mat into temp
sort lines of trow ascending numeric by word 1 of each #keys are random sometime
put the last line of temp into rows
#columns
put the keys of mat[1] into temp
sort lines of temp ascending numeric by word 1 of each #keys are random sometime
put the last line of temp into cols
# let's creat a simple text file
put empty into tmat
repeat with i = 1 to rows
repeat with j = 1 to cols
put mat[j] & "" after tmat
end repeat
put return after tmat
end repeat
answer tmat
end visualizzamatrix

Is it ok for you?
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

laouris
Posts: 5
Joined: Sun Nov 13, 2016 1:46 pm

Re: How to retrieve a column array from a 2-D array?

Post by laouris » Mon Feb 28, 2022 10:10 pm

I still don't get it how I can retrieve a ROW from the 2D array. Any help there? How can we edit the function for GetArrayColumn to create a function GetArrayRow? Rows do not have names -;)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9579
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to retrieve a column array from a 2-D array?

Post by dunbarx » Mon Feb 28, 2022 10:39 pm

Hi.

Old thread.

Arrays in LC are not really built the way you are asking. That is, if I actually understand what you are asking. So let's say you have the following dataSet:
1,dog,friend
2,cat,foe
3,bird,nuisance
4,duck,dinner
In plain English, assuming we had this in some form of array, what do you want out of, say, row 2? Is it:
dog
cat
bird
duck
??
Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9579
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to retrieve a column array from a 2-D array?

Post by dunbarx » Mon Feb 28, 2022 10:57 pm

Looking back over the thread, I see this by Sri (breakpoint by me):

Code: Select all

on mouseUp
 put "blue" into a[1][1]
   put "green" into a[2][1]
   put "yellow" into a[3][1]
   put "red" into a[4][1]
   put "lemon" into a[1][2]
   put "orange" into a[2][2]
   put "peach" into a[3][2]
   put "pineapple" into a[4][2]
   breakpoint
end mouseUp
At the breakpoint, you have "built" an array where elements has been assigned to certain "locations" for each key. Perhaps you can say which elements would comprise the "row" that you are trying to extract?

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”