LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array of Clusters to CSV

Solved!
Go to solution

How do you recommend turning an array of clusters (containing only doubles and strings) to a CSV file (or Excel spreadsheet)?

0 Kudos
Message 1 of 8
(8,142 Views)

Unbundle the cluster (in an indexed loop), convert to strings, add required delimiters, write to CSV file.  I can't be more specific unless you post your cluster.

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
Message 2 of 8
(8,135 Views)

You could pass the array into a for loop.

Then for each cluster, use Cluster to Array, and pass that array out of the for loop.

It will then auto-index into a 2D array for you.

You can use Write to Spreadsheet File to write this 2D array to a CSV.

Cory K
0 Kudos
Message 3 of 8
(8,130 Views)

Will Cluster to Array work with mixed data types?  I don't think it's smart enough (or I'm not...).

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
0 Kudos
Message 4 of 8
(8,127 Views)

 


@NIquist wrote:

Will Cluster to Array work with mixed data types?  I don't think it's smart enough (or I'm not...).


Umm I'm not sure I didnt try.
But if it doesn't, it wouldn't hurt anything if you just typecasted everything to strings, because you're writing it to a text file anyway, so it won't care

 

Cory K
0 Kudos
Message 5 of 8
(8,123 Views)
Solution
Accepted by topic author CodeSDz

Basically what NIquist said, but I would encourage you to use Format Into String, one of those rare moments in LV when the terminals from Unbundle align nicely with the terminals in Format Into String.

 

ClusterToCSV.png

 

Hint:  To get the format string, first wire the connections then right click Format Into String and select 'Edit Format String'.  The floats and strings are already there for you, just add the commas (or \t) and the \n and you are done.

Message 6 of 8
(8,104 Views)

I went with this solution.  Easy enough for a temporary solution.

 

Just thought maybe there was a built-in method that would work on any cluster instead of coding for a specific one.

0 Kudos
Message 7 of 8
(8,091 Views)

 


@StevenATK wrote:

I went with this solution.  Easy enough for a temporary solution.

 

Just thought maybe there was a built-in method that would work on any cluster instead of coding for a specific one.


 

I think the problem lies with the data type(s) that are inside the cluster.

It is difficult to make a single, simple function because clusters can have any number of things inside, not necessarily of the same data type.

They can have simple things inside such as ints, dbls, strings, etc but they could also have nested clusters, arrays, etc which would make it very difficult to write to a file.

Cory K
Message 8 of 8
(8,083 Views)