combining arrays

Discuss problems and solutions.
electrofux
Regular
Posts: 294
Joined: 24 Jan 2012 18:22

combining arrays

Post 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'}

?
Phil999
Regular
Posts: 919
Joined: 11 Jan 2012 01:53

Re: combining arrays

Post 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.
Formant+Eurorack, PPG wave 2.2, Korg MS-20, etc., EWI 4000s, QuNeo, etc., Mixbus32c, u-he, MadronaLabs, Samplemodeling, NI, etc., iPad2/4/Pro
electrofux
Regular
Posts: 294
Joined: 24 Jan 2012 18:22

Re: combining arrays

Post 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?
Phil999
Regular
Posts: 919
Joined: 11 Jan 2012 01:53

Re: combining arrays

Post 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.
Formant+Eurorack, PPG wave 2.2, Korg MS-20, etc., EWI 4000s, QuNeo, etc., Mixbus32c, u-he, MadronaLabs, Samplemodeling, NI, etc., iPad2/4/Pro
Macciza
Regular
Posts: 1315
Joined: 07 Dec 2011 04:57
Location: Sydney, Australia.

Re: combining arrays

Post 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 . .
iMac 2.8G i7 12G 10.6.8/10.7.2, Legacy Dexter/Lemur, Liine Lemur/iPad2, KMI SoftStep, 12Step & QuNeo , B-Controls, Mackie C4 etc
MaxMSP, Live Suite, Native Instrument stuff, etc Modified Virtual Guitar System etc All Projects/Modules © CC-BY-NC-SA[*][/b]
electrofux
Regular
Posts: 294
Joined: 24 Jan 2012 18:22

Re: combining arrays

Post 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.
Macciza
Regular
Posts: 1315
Joined: 07 Dec 2011 04:57
Location: Sydney, Australia.

Re: combining arrays

Post by Macciza »

Hi
Simply d={a,b,c} . . .
iMac 2.8G i7 12G 10.6.8/10.7.2, Legacy Dexter/Lemur, Liine Lemur/iPad2, KMI SoftStep, 12Step & QuNeo , B-Controls, Mackie C4 etc
MaxMSP, Live Suite, Native Instrument stuff, etc Modified Virtual Guitar System etc All Projects/Modules © CC-BY-NC-SA[*][/b]
Phil999
Regular
Posts: 919
Joined: 11 Jan 2012 01:53

Re: combining arrays

Post by Phil999 »

yes, adding and interlacing do different things.
Formant+Eurorack, PPG wave 2.2, Korg MS-20, etc., EWI 4000s, QuNeo, etc., Mixbus32c, u-he, MadronaLabs, Samplemodeling, NI, etc., iPad2/4/Pro
Macciza
Regular
Posts: 1315
Joined: 07 Dec 2011 04:57
Location: Sydney, Australia.

Re: combining arrays

Post 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
iMac 2.8G i7 12G 10.6.8/10.7.2, Legacy Dexter/Lemur, Liine Lemur/iPad2, KMI SoftStep, 12Step & QuNeo , B-Controls, Mackie C4 etc
MaxMSP, Live Suite, Native Instrument stuff, etc Modified Virtual Guitar System etc All Projects/Modules © CC-BY-NC-SA[*][/b]
electrofux
Regular
Posts: 294
Joined: 24 Jan 2012 18:22

Re: combining arrays

Post 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.
Post Reply