09-10-2012 07:22 AM
Hi All,
I'm trying to use the Array SetElements function to set a value to specific indices within an initialized array but I cannot figure out what the syntax is for the optional parameter 2. I've tried a whole bunch that seem to make sense but always get an error. Has anyone used this function before who can let me know what the syntax to use is?
Thanks,
Nick
Solved! Go to Solution.
09-11-2012 10:44 AM
Nick,
So the syntax for setting all of the elements to a value can simply be written:
SetElements( myArray,valueToSet )
To add in the optional parameter 2 and define a range is something like this:
SetElements( myArray,valueToSet, "[3..6]" )
The .. operator is analagous to a : in Matlab.
Good luck,
Chris
09-12-2012 02:14 AM
Hi Chris,
Thanks for the reply. I think I tried this format but couldn't get it to work for non ranged elements. What would the syntax be for setting elements 1, 3, 4, 8 etc..?
Thanks,
Nick
09-12-2012 08:45 AM
The SetElements function does not support non-contiguous ranges of elements, so there's not much point in using it if you aren't going to set the whole array or a range of elements. You can just do:
array[1] = 0,
array[3] = 0,
array[4] = 0,
array[8] = 0,
-Doug
09-12-2012 10:25 AM
Hi Doug,
Thanks for the response, this is the workaround I have been using. It would have been so much neater the other way though. Ah well can't have it all I guess.
Thanks again,
Nick