03-20-2013 10:13 AM
Hello,
I use the function buildArray to build a 1D array of 1024 elements.
Aferwards I want to extract all elements + the index of all elements for another purpose.
I mean If for ex. the 1st element of my array is 10, the second is 45, the third is 65, I want to have (0,10), (1, 45), (2, 65).
Can you please help me.
Solved! Go to Solution.
03-20-2013 10:22 AM
Use a FOR loop. Autoindex your array. Use Build Array inside of the FOR loop to create an array of the index (from the i terminal) and your indexed element. Wire the new array to output from the FOR loop (again, use autoindexing) to create a 2D array.
03-20-2013 10:23 AM
thanks a lot
03-20-2013 10:24 AM
Do you want the data to be returned as strings in the format you provided in your example? If so you can generate them at the same time you are creating your array. Sinply use the Format Into String VI. Your format specifier would be "(%d,%d)". Wire the i value of the loop to the first input and the data value to the second.
03-20-2013 10:25 AM
I am not sure how you are getting the numbers for the 1024 size array so I am making some assumptions here. If you take the 1D array and make it a 2D array you can add number in the first colum and data in the second.
If you are indexing to a paticular place int he array you could build a 2D array using the index value and the actual value. It is not clear what you are trying to do.
03-20-2013 10:35 AM
I don't see the need for a 2-D array if the first column is simply going to contain the index. You have this same information using a 1-D array. It is the index of the element. There is no need to repeat the index value in the 2-D array. The exception would be if you are going to perform various sorts of the data and need to maintain the order of the initial data set.
03-20-2013 10:38 AM
It would depend on what is going to happen with the data and the end result that he is looking for. It sounded to be that he was going to build an array of values and their indexes for output to a file. That would require a 2D array or 2 1D arrays.
03-20-2013 11:06 AM
@aeastet wrote:
It would depend on what is going to happen with the data and the end result that he is looking for. It sounded to be that he was going to build an array of values and their indexes for output to a file. That would require a 2D array or 2 1D arrays.
If you were outputting the data to a file you still only need a single 1-D array containing the values. As you iterate over the array simply use the i value of the for loop as the index value. A 2-D array is only required if you sort the data and need to know the initial position of the element.
03-20-2013 11:09 AM
Thank you all for your responses.
In fact,my problem is a little bit different from just having arrays and indexes.
All I want to do is to plot my 1024 values on a XY graph, in which my Y values are my 1024 values, and my X values are integers from 1 to 1024.
That is why I think to build an array of my 1024 values and use theirs index to put on my X axes.
However I can not get all indexes from my 1D array.
Thank you for your help