05-22-2020 12:15 PM
Hi,
I am building a saving VI that takes a generic cluster and converts all of its contents into strings [first column variable name, second column variable] so I can use the 'write delimited spreadsheet' VI. I figured converting the cluster to variant, then accessing the elements of the cluster with the 'get cluster information VI' in the variant palette, then specify what to do with each data type would do the job.
Everything went well until I tried to extract an array, it doesn't spit any errors, but returns a blank array. I've attached a simplified code snippet -- I can't figure out what I'm doing wrong.
I have also attached the more complex VI I'm working on.
Solved! Go to Solution.
05-22-2020 01:04 PM
So I've found a workaround. It turns out you can convert the cluster into an array of variants first and this works, although I find it a bit inelegant. I'm still unsure of what was wrong with my original thinking.
05-22-2020 01:13 PM - edited 05-22-2020 01:15 PM
Wouldn't is be simpler to just convert your numeric array to strings first?
Here's an example:
Then then create a string array with your headers and write it with "write delimited spreadsheet.vi".
BTW: the %S format makes the string an exact duplicate, it does not do any digits of precision conversion.
05-22-2020 01:16 PM - edited 05-22-2020 01:21 PM
@pablo.doc wrote:
So I've found a workaround. It turns out you can convert the cluster into an array of variants first and this works, although I find it a bit inelegant. I'm still unsure of what was wrong with my original thinking.
You are wrapping your data within a cluster. You need to decode it the same way:
Edit:
Oops, I see you wanted it as an array. Forget the FOR loop.
05-22-2020 01:50 PM
Get Cluster Information.vi returns an array of variants each containing the elements type and not the values. You need to store the flatten string form of the original data as well to be able to convert it back:
05-22-2020 02:10 PM - edited 05-22-2020 02:13 PM
Hi RTSLVU,
@RTSLVU wrote:
BTW: the %S format makes the string an exact duplicate, it does not do any digits of precision conversion.
Can you provide any reference for this information in the LabVIEW help?
Apparently it does some "digits of precision conversion"…
05-22-2020 02:11 PM - edited 05-22-2020 02:12 PM
WOW this thread is becoming more Rube Goldberg by the minute.
Do me a favor and upload an actual copy of your cluster containing some sample data.
I am obviously missing something as your small example makes what you are doing an over complicated solution to something as simple as saving a numeric array to a file
05-22-2020 02:31 PM - edited 05-22-2020 02:32 PM
@GerdW wrote:
Hi RTSLVU,
@RTSLVU wrote:
BTW: the %S format makes the string an exact duplicate, it does not do any digits of precision conversion.
Can you provide any reference for this information in the LabVIEW help?
Apparently it does some "digits of precision conversion"…
I can't actually find anything but I have been doing this for years. You can specify the number of decimal places like this %.3S converts to a string with three decimal places
LabVIEW's normal rounding and numeric limitations do apply
05-22-2020 02:52 PM
Hi RTSLVU,
@RTSLVU wrote:
I can't actually find anything but I have been doing this for years. You can specify the number of decimal places like this %.3S converts to a string with three decimal places
Then why do you use "S" when you want to use "f" (or any other format code for floats) instead? As can be seen in my image above "%S" behaves the same as "%f" with a default of 6 decimal places.
(IMHO this "S" is a bug within ArrayToSpreadsheetString: this format code results in an error when you want to use it with FormatIntoString. I guess it only works with ArrayToSpreadsheetString because NI doesn't want to "unfix" code running for years with this undocumented/wrong format code…)
05-22-2020 03:33 PM - edited 05-22-2020 03:33 PM
There are quite a few libraries out there that do cluster to string conversion. The OP might want to look into a couple of those to learn some of the techniques. A recent one that I have written is JSONtext, available on the Tools Network.