Page 2 of 2

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

Posted: Thu Jun 19, 2014 2:55 pm
by MaxV
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?

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

Posted: Mon Feb 28, 2022 10:10 pm
by laouris
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 -;)

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

Posted: Mon Feb 28, 2022 10:39 pm
by dunbarx
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

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

Posted: Mon Feb 28, 2022 10:57 pm
by dunbarx
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