LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

arrays of values with assorted units

Hi,

I am a LV 6i/Mac user and I have been working with dimensionless (without units) numbers until now. Lately I am trying to implement a physical model, where LV's ability to keep track of units and do the automatic conversions is a bonus. Things can get messy with a simple numerical integration, so it's a lot of help.

However, I noticed some downfalls. I would like to store my data in a 2D array, where each column belongs to a different quantity, i.e. has different units. I need this in order to utilize the way I save data in files, which is just text (spreadsheet) representation of the described array, with an appropriate header line. I wasn't able to build such a 2D array, the wires stay broken because of the incompatible units. The only solution I found of is to divide all values by a "1" of the same units, which gives me dimensionless numbers, and then plug those in the output array. The same goes to the fact that if I am saving for example an energy value with units, it gets always saved in joules (SI units). To enforce a record in electronvolts I have to divide it by "1.00" joule and then by a (dimensionless !) electron charge.

Does anybody have a neater way to get around my problem?

Thanks all!
Daniel
0 Kudos
Message 1 of 6
(2,550 Views)
You could format all of your data into strings and then combine these strings to write into the file.  You can define your string format to include the appropriate unit conversion.  The unit will be included as part of the string, but you could strip this off if desired.
 
This works on LV 7.1 on PC, but I'm assuming that the functionality is the same on 6i on Mac.
Message 2 of 6
(2,544 Views)
Thank you John, I will look into the conversion format string tricks. The LV user manual barely mentions formatting strings, the Functions/String/Conversion functions (at least in the 6i version for Mac) don't mention "units" in the Format string. Could you tell me, which function you'd use and what the format string syntax is to accommodate units, please?
Daniel
0 Kudos
Message 3 of 6
(2,539 Views)
The "Format Value" function under the "String/Number Conversion" subpallete of the "String" pallete.  You can look at the help to determine exactly how you want to format the string.  There are many things that you can do to the string using format strings.  One way that I've found handy to learn about new functions is to write a small vi that just allows me to change a certain aspect (in this case the format string) and see the results.  One solution would be a format string of %1.2{unit}, where unit is the appropriate unit.
Message 4 of 6
(2,535 Views)
Excellent, John,
I found nothing at all about the placing of units info in the formatting string in the LV 6i help, but your suggestion has worked. I had to play with it a bit to determine the behavor of other format specifiers, as %1.2g{units} does not work properly, while %1.2{units}g DOES! Now this way I can cross my old file formats with the internal convenience of the use of units.
Thank you very much!
0 Kudos
Message 5 of 6
(2,526 Views)
I'm glad to be of help.
0 Kudos
Message 6 of 6
(2,512 Views)