LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

read elements and index of an array

Solved!
Go to solution
Highlighted

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.

 

 

 

 

0 Kudos
Message 1 of 9
(1,820 Views)
Highlighted
Solution
Accepted by topic author joobin

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Message 2 of 9
(1,813 Views)
Highlighted

thanks a lot

0 Kudos
Message 3 of 9
(1,808 Views)
Highlighted

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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 4 of 9
(1,807 Views)
Highlighted

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.

 

Tim
GHSP
0 Kudos
Message 5 of 9
(1,805 Views)
Highlighted

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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 6 of 9
(1,791 Views)
Highlighted

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.

Tim
GHSP
0 Kudos
Message 7 of 9
(1,787 Views)
Highlighted

@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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 8 of 9
(1,772 Views)
Highlighted

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

0 Kudos
Message 9 of 9
(1,770 Views)