From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Getting an extra dimension when unbundling array of clusters

Solved!
Go to solution

Hello,
I am trying to export some data using the write to spreadsheet function. I get the spectra from a CCD camera using a VI I found in this post. That VI works perfectly, I can get the wavelength vs intensity plots on the front panel. The problem is, that the data comes in the form of "1D array of cluster of 2 elements" so I unbundle the clusters to get a 2D array which I could save as a spreadsheet but somehow I end up getting a 3D array. I have tried saving the 3D array into a text file as is and it only shows me the wavelengths and respective intensities. I reckon I might have caused lab view to just add an empty row as a 3rd dimension. I would highly appreciate it if you could help me turn this into a 2D array that I can export normally. I added the VI in question and some pictures.

Spoiler
it says that array is 3dit says that array is 3dthis is good that's how it should lookthis is good that's how it should lookwrote the 3d array to a text filewrote the 3d array to a text filethis is the text file (I basically wanted to have this but without that (0,0,0) and with x and y in columns instead of rows. Is there another way to do that)this is the text file (I basically wanted to have this but without that (0,0,0) and with x and y in columns instead of rows. Is there another way to do that)
0 Kudos
Message 1 of 5
(2,538 Views)

Hi asteele,

 

but somehow I end up getting a 3D array.

Not "somehow", but due to your programming…

The cluster consists of 2 1D arrays. You build a 2D array from those 2 arrays. Then you have that FOR loop to autoindex in input array of clusters and to autoindex your 2D arrays - which results in a 3D array!

 

I would highly appreciate it if you could help me turn this into a 2D array that I can export normally.

Place the exporting file function inside your loop…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(2,528 Views)
Solution
Accepted by topic author asteele77

use concatenation

concatenate.png

Message 3 of 5
(2,525 Views)

I started writing a longer, general response, but before finishing saw that other answers were already posted.  I ended up exactly where Artem.SPb did, I just took a more roundabout route.   Read on if interested...

 

 

-Kevin P

 

P.S.  GerdW's reply is a good approach too and is better suited for the more general case described below.

 

-----------------------------------------------------------------------------------------

 

Actually, I kinda think your *goal* might be the problem.  Your array of clusters of arrays of data is a *helpful* data structure that keeps related things (wavelength & intensity) associated correctly.   Each element of the cluster array is a distinct chunk of plottable data that belongs together.  If you were to smush all that data into a pure 2D array, you then need some further means to delineate one plot-worth of data from the next.

 

Since the sizes of the arrays in one cluster element can be different than the sizes in the next, I kinda think the desire to smush everything into a 2D array might be an ill-advised goal.  It might be better to make your own code for writing this kind of data to file in a format that more clearly delineates the data associations.

 

Now a lot of that is general thought.  It turns out that you have a specific app involving image capture so I *suspect* each cluster element contains same-sized arrays of data.  So *only* because of your special case, there should be a reasonable workaround where you make a 2-D array where the # columns is 2x the # of elements in your cluster array and the # rows is equal to the size of the arrays inside each cluster element.

 

...[time passes]  So it turns out that the fix to your original code is very simple.  Instead of *indexing* your 2D array at the For loop output tunnel, right-click and change it to *concatenate* mode.  That's it! 

   But it's important to remember that this simple solution absolutely depends on your special case where the arrays inside each cluster element keep having the exact same size.  The general usage for arrays of clusters of arrays allows for variable size contents and this simple solution would have a lot of side effects (basically, all shorter rows would get padded with 0 values to have the same length as the longest rows.  And then those rows get turned into columns by the transpose operation)

 

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 4 of 5
(2,511 Views)
Solution
Accepted by topic author asteele77

It looks like WinXControl is producing multiple Spectra, one per channel, each spectrum being a Cluster of a Wavelength array and an Array Constant (?) array (which I assume are the Spectrum values).  This Array of Cluster configuration is ideal for plotting multiple XY graphs (you need three dimensions -- X, Y, and a dimension for each plot).  Since the outermost dimension represents the "Channels" that you are analyzing (which might only be one channel!), you want to do all of the "single channel" computation inside the For loop.  Unbundle the Cluster to get 2 1D arrays (Wavelength and Array Constant), do whatever you need to do to these data (I don't remember whether LabVIEW 2014's Write to Spreadsheet function allows you to do the Transform as a Boolean Input to the function itself), and then let the For Loop "loop" to handle any other Channels you might want to save.  Of course, if you do have multiple Channels, you probably will need multiple File Names, as this is not Microsoft Excel, where you can have multiple named WorkSheets.

 

Bob Schor

Message 5 of 5
(2,508 Views)