Page 1 of 2

combining arrays

Posted: 21 Oct 2013 14:17
by electrofux
Hello,

i have two array looking like this:

arrayA={'Instrument1','Instrument2'}
arrayB={'Thor','Antidote'}

is there a way to combine those two to get:

arrayC={"Instrument1 Thor",'Instrument2 Antidote'}

?

Re: combining arrays

Posted: 21 Oct 2013 18:19
by Phil999
I think with subarray you can separate arrayA and arrayB. Then just combine the subarrays into one array.

A1=subarray(arrayA,0,length)
A2=subarray(arrayA,start,length)
B1=subarray(arrayB,0,length)
B2=subarray(arrayB,start,length)

arrayC={A1,B1,A2,B2}

if I'm not mistaken, this should work. Haven't tried it out yet.

Re: combining arrays

Posted: 21 Oct 2013 21:41
by electrofux
Thats not quite what i am after though i think it got me a step nearer. What i want to do is set the 2 labels of a switch object to 1) "Instrument1 Thor" and 2.) "Instrument2 Antidote". Therefor i must combine the values of the two arrays into one item each.

I have interlaced the two arrays now, so i have arrayC={'Instrument1', 'Thor', 'Instrument2', 'Antidote'} but i am struggeling to set the labels to 2 consecutive arrayitems.

There are no arrays of arrays in Lemur, are there?

Re: combining arrays

Posted: 21 Oct 2013 21:57
by Phil999
there are, just like

arrayC={A1,B1,A2,B2}

the arrays between {} separated by a comma, are consecutively combined. Tested now, and it's true.

Maybe still not what you're looking for, but with the above method we can combine arrays, and with subarray() we can extract portions of an array.

Re: combining arrays

Posted: 22 Oct 2013 03:34
by Macciza
Hi
The crux of your problem is that you are really talking about 'strings' here rather than 'arrays' as such . . .
Remember how we got the 'Thor' text in the first place - as an ASCII array which we then converted . . .
If you can get the 'Instrument 1' text the same way then it is simply a matter of combining those arrays (maybe add a space between them) and then arraytostring() on them
You can otherwise create and store the strings as ascii arrays if they are not being sent . . .

So if INST1 and THOR are variables with the ascii arrays needed and SPACE =32 (ascii for space) then arraytostring(INST1,SPACE,THOR) returns "Instrument1 Thor"

I believe they have been working on implementing built-in String functions at some point so this will change when they are introduced . . .

Hope that helps . .

Re: combining arrays

Posted: 22 Oct 2013 22:42
by electrofux
Ok i am nearly at it then. But what is the best way to make one array out of three?

Example:
a={34,55}
b={32,32}
c={44,46}

d={34,55,32,32,44,46}

Is there an easy way or do i have to loop through everything and built a new one? Simply adding doesnt really work, interlace mixes everything up.

Re: combining arrays

Posted: 22 Oct 2013 23:37
by Macciza
Hi
Simply d={a,b,c} . . .

Re: combining arrays

Posted: 23 Oct 2013 00:11
by Phil999
yes, adding and interlacing do different things.

Re: combining arrays

Posted: 23 Oct 2013 01:54
by Macciza
Yes
Adding arrays is a maths operation that adds the array contents together - so d=a+b+c would give {110,113} in this instance
Interlace and interlace3 take successive values from each array to be place sequentially in the new array

Re: combining arrays

Posted: 23 Oct 2013 12:58
by electrofux
hm, i think i tried arraytostring({a,b,c}) and that didnt gave me the right result but i have to try again. Maybe first d={a,b,c} and then arraytostring(d).

I will try again tonight, thx for the help.