LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Cluster to variant question

Solved!
Go to solution

I want to do the following: convert my colorimetric cluster into a string array that I can ultimately write to a delimited spreadsheet VI

 

LED47_0-1708015022139.png

I'm having trouble understanding how to set the data type to do this

0 Kudos
Message 1 of 10
(628 Views)
Solution
Accepted by topic author LED47

I can't seem to relate the subject of the topic to the question so I will ignore the subject.  You do NOT have a "Cluster to variant question"; you have a "How do I convert the values of the elements inside my cluster to an array of strings" question.  You will have to unbundle each element of the cluster and use the appropriate number to string conversion function in the String --> Number/String Conversion palette.  This has nothing to do with variants.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 10
(621 Views)

 

Expanding on the comment made by @billko, your goal is poorly defined.

 

Consider the cluster you provided.  You have two quantities that appear to be a value-unit pair (RadInt + RadIntUnit, and PhotInt/PhotIntUnit pair) and possibly a third (ScotopicInt and CalibrationUnit), which (despite the "Int", suggesting "integer") are a Dbl + String pairing, followed by 23 Dbls followed by an Array of Dbls (of unspecified size).

 

In the code fragment you provided, you convert it to a Variant.  Why?  You then follow this by a Variant-to-Data, but do not specify the format you desire for the data (this makes no sense, at least, not to me).  Now, you could do what I just did and wire the Cluster coming from "Colormetric" into the top of the Variant-to-Data to get the Cluster back, which is pretty instructive:

Colormetric Cluster.png

Look at the indicator "data".  If you get rid of the three Strings at the top, you have a 26 rows x 1 column array (which you can output with one "Write Delimited Spreadsheet" command, followed by a 1 row x ?unknown? columns array (which can also be output by one Write Delimited Spreadsheet" command.  But what a mess ...

 

My advice is to go back to the drawing board and reorganize your Project.  Are the "vertical" data (the 26 x 1 array) coming in at the same rate as the "horizontal" (1 x ?? array) data?  Maybe the only seriously-time-varying data are the latter data points?

 

Bob Schor

 

 

0 Kudos
Message 3 of 10
(574 Views)
Solution
Accepted by topic author LED47

Maybe this helps:

 

Convert cluster to readable string and string to data, but not UTF-8? - NI Community

 

Maybe not 😁. Variants are a wild beast, hard to tame.

 

Converting a cluster to variant is simple (and quite pointless):

wiebeCARYA_0-1708074139045.png

Converting a cluster (or variant of cluster) to an array of variants is quite useful:

wiebeCARYA_1-1708074236757.png

You'd normally loop over the items, and convert them to string based on type. 

wiebeCARYA_2-1708074481401.png

However, this should be done in a recursive way, as a cluster can contain a cluster (arrays contain elements, but can contain clusters containing arrays, etc.). Enums are tricky too. Do you store the numbers or their strings? Both have there ups and downs.

 

Note that you can get away with one case for I8, I16, I32, I64 and one for U8, U16, U32, U64, and probably one for sgl, dbl, ext. Some for U8, U16, U32, U64 enums

 

Of course, if you don't have recursive types or don't want to support them, it's easier.

Message 4 of 10
(564 Views)
Solution
Accepted by topic author LED47

The normal/classic way of doing it:

Yamaeda_0-1708079434825.png

 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 5 of 10
(552 Views)
Solution
Accepted by topic author LED47

Thank you to everyone the basic explanation of using variants, I find this forum to be an invaluable resource.

Message 6 of 10
(539 Views)

I'd like to put in a good word for the MGI Read/Write Anything toolkit when you want to convert any arbitrary cluster into a human-readable string and later recover that cluster from the string. 

 

The top level API function deals with .INI format files, but dig down just one level and you find nuggets like "String to Anything" and "Anything to String".  (Note that these are nearly, but not quite symmetric functions, meaning that you can't quite run the output of one directly into the input of the other to recover your original data.  S2A takes in a multi-line string, A2S puts out an array of single-line strings.  Not the same, but pretty trivial to convert as needed.)

 

 

-Kevin P

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).
Message 7 of 10
(521 Views)

Thank you

0 Kudos
Message 8 of 10
(512 Views)

wiebe@CARYA wrote:

Maybe this helps:

 

Convert cluster to readable string and string to data, but not UTF-8? - NI Community

 

Maybe not 😁. Variants are a wild beast, hard to tame.

 

Converting a cluster to variant is simple (and quite pointless):

wiebeCARYA_0-1708074139045.png

Converting a cluster (or variant of cluster) to an array of variants is quite useful:

wiebeCARYA_1-1708074236757.png

You'd normally loop over the items, and convert them to string based on type. 

wiebeCARYA_2-1708074481401.png

However, this should be done in a recursive way, as a cluster can contain a cluster (arrays contain elements, but can contain clusters containing arrays, etc.). Enums are tricky too. Do you store the numbers or their strings? Both have there ups and downs.

 

Note that you can get away with one case for I8, I16, I32, I64 and one for U8, U16, U32, U64, and probably one for sgl, dbl, ext. Some for U8, U16, U32, U64 enums

 

Of course, if you don't have recursive types or don't want to support them, it's easier.


BD is slightly cleaner if you use "Get Cluster Information.vi" instead of "Variant to Data".

paul_cardinale_0-1708109780133.png

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 9 of 10
(494 Views)

@paul_cardinale wrote:

wiebe@CARYA wrote:

Maybe this helps:

 

Convert cluster to readable string and string to data, but not UTF-8? - NI Community

 

Maybe not 😁. Variants are a wild beast, hard to tame.

 

Converting a cluster to variant is simple (and quite pointless):

wiebeCARYA_0-1708074139045.png

Converting a cluster (or variant of cluster) to an array of variants is quite useful:

wiebeCARYA_1-1708074236757.png

You'd normally loop over the items, and convert them to string based on type. 

wiebeCARYA_2-1708074481401.png

However, this should be done in a recursive way, as a cluster can contain a cluster (arrays contain elements, but can contain clusters containing arrays, etc.). Enums are tricky too. Do you store the numbers or their strings? Both have there ups and downs.

 

Note that you can get away with one case for I8, I16, I32, I64 and one for U8, U16, U32, U64, and probably one for sgl, dbl, ext. Some for U8, U16, U32, U64 enums

 

Of course, if you don't have recursive types or don't want to support them, it's easier.


BD is slightly cleaner if you use "Get Cluster Information.vi" instead of "Variant to Data".

paul_cardinale_0-1708109780133.png


But you loose the data in the elements.

 

Get Cluster Information only returns the variant data types with default data values.

wiebeCARYA_0-1708336406848.png

0 Kudos
Message 10 of 10
(326 Views)