LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

creating a matrix of arrays

Hi,

 

can somebody please help me how I can create a matrix of arrays in LabVIEW?

 

So, I need to create a matrix and initialize its elements with an empty array. The aim is that while I am doing the evaluation of my sensor matrix with a for loop sequentially, I can store the data of the sensors into the respective arrays in each scan period.

 

Is there any efficient method to save such a matrix into [text] files?

 

Doing such a data recording, is there some special condition which I must pay particular attention to?

 

Thanks,

Krivan

Message 1 of 16
(5,548 Views)

You can't have an array of array's.  But you can have an array of clusters, and the element of the cluster can be an array.

Message 2 of 16
(5,535 Views)
Since the number of sensors is constant per run, use a 3D array. You can autoindex your 2d array at the loop boundary to create it. You can save the 3D array as a binary file.
Message 3 of 16
(5,519 Views)

LabVIEW autoindexes off of the first dimension of an array and additional dimensions go to the front of the size vector. For example, an array with 3 rows, 4 columns and 5 pages would have the size vector [5 3 4] and autoindex through the 5 pages if passed into a for loop. This convention is different than other programs (like MATLAB) who put additional dimensions at the end The aforementioned array would have a size [3 4 5] in MATLAB.

Andrew
Message 4 of 16
(5,506 Views)

 


@arcranda wrote:

LabVIEW autoindexes off of the first dimension...


In what way is this reply related to the question discussed in this thread? Just wondering.

 

Message 5 of 16
(5,500 Views)

The original poster asked if there were special conditions he had to be aware of when using matrices. LabVIEW's array size convention and autoindexing are unique. I figured it would be prudent to mention their caveats before somebody tried to do a lot of manipulation with multidimensional arrays.

Andrew
Message 6 of 16
(5,492 Views)

Pardon me if you already know how to do this, but you may find 2-dimensional arrays your most useful solution.

 

You can think of them like an array of 1-D arrays if you need to. Like a table in excel with rows and columns.  This really comes in handy with data acquisition where rows can be sample number and columns can be channels.

 

Using 2D arrays will:

1 allow you to initialize the arrays to blank arrays using the initialize array function

2 allow you to utilize the auto-indexing feature of for loops. In text based languages you have to explicitly tell the program how to iterate through the loop, labview automatically iterates through all the elements in the top dimension of an array and stops (by default)

3 Writing two dimensional arrays to file is simple. You just wire the array into the write to spreadsheet function and tell it where to save the file.

 

How a 2D array works.png

---------------------------------
[will work for kudos]
Message 7 of 16
(5,483 Views)

I forgot to mention some recording caveats to keep in mind: 

 

1. In general reading or writing anything to file is slower than working with it in memory. So try to work the the array in memory as much as possible and only write to file when you need to.

 

2. Binary read/write functions are the fastest to read from and write to, but working with them is real low level, tedius work. TDMS is second fastest and is a lot more intuitive to work with. Then comes the write to spreadsheet and text file functions.

---------------------------------
[will work for kudos]
Message 8 of 16
(5,475 Views)

Can we backup to the beginning and try to understand the problem?

 

Typically a matrix is a 2D array, so a matrix of 1D arrays (or a 1D array of matrices) is similar to a 3D array.

 

Krivan, can we get the terminlogogy a bit clearer? Could you attach a simple VI containing your data structures? Thanks!

Message 9 of 16
(5,468 Views)

Hi,

 

yes, I think the 3D array will describe the most what I want. It should be a 2D array that has array elements, so it is a 3D array.

Using rex1030's advice I attached a code how I thought a 3D array is made but I somehow couldn't get it right how I can achieve that the elements of the 2D array were arrays. It was quite easy to do in Java some time ago but in Labview I'm struggling with it a bit...

 

Thanks for the replies so far!

0 Kudos
Message 10 of 16
(5,431 Views)