LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can .lvm hold a struct?

Hey guys,

 

I would like to replace the use of a .mat file that holds a struct with the use of a .lvm file. Is it possible?

 

..I've used .lvm file to replace simple tables of data stored in .mat, but never a structure...any help is most welcome,

 

 

Adrian

0 Kudos
Message 1 of 7
(3,251 Views)

A .lvm file is just a text file that has a specific format. Unfortunately, you cannot wire a cluster directly to the Write to Measurement File VI.

 

You mentioned .mat files. Are you trying to transfer data between LabVIEW and Matlab?

0 Kudos
Message 2 of 7
(3,239 Views)

 

hey,

 

that is exactly what I am doing. trying to get rig of some Matlab coding using Mathscript. and part of the problem at hand is a .mat file that holds a structure.

 

is there any other kind of file that LabView has that better suits this issue?

 

thanks for your answer,

 

Adrian

0 Kudos
Message 3 of 7
(3,224 Views)

LV can write plain text files easily.

 

Additionally, if you have structures you'd like to emulate in LV, you can do so by creating a Cluster.

 

A Cluster is LVs answer to structs, and allows you to place (and label) data types inside of it. You can then put Clusters in Array Constants to make arrays of clusers (or array constants into clusters, etc).

 

Reading and writing a cluster (with the data in it) to a file can be done a vatiety of ways depending on how you want the data to look, but one of the simpler and easier ways is to use the XML generating functions to make an XML string and then writing it a file.

 

Off the top of my head, I seem to remember a 'Flatten to XML' file which produces a text from a Cluster and then you can use 'Write to text file' (which writes generic strings to text files)  or 'Write XML file' (which writes XML to text files). This is great, because you can then open the text file later in LV and then 'Unflatten XML' to rebuild the Cluster from the file with all the data goodness there too.

 

Obviously, there's a million and one ways to format a structure in labview and write it to a file depending on the format you want.

 

See maybe http://zone.ni.com/reference/en-XX/help/371361F-01/lvhowto/writing_datalog_files/

 

I hope I understood your problem and got you closer to an answer!

0 Kudos
Message 4 of 7
(3,197 Views)

There are many ways to save clusters to file:

  • You could write to a binary file.
  • You could write to an XML file using the LabVIEW XML schema. This uses the Flatten to XML and Unflatten from XML functions.
  • You could write to an XML file using your own XML schema. This would use the XML Parser VIs (if you have LV 8.6 or above), or a thirdy-party XML library such as LabXML or JKI's Easy XML package.
  • You could write to a text file using your own format.
  • ...

0 Kudos
Message 5 of 7
(3,194 Views)

thanks a lot guys,

 

I'm tackling the problem as we speak...cluster creating and testing...i'll let u know how it's going before considering the problem as solved 🙂

 

Adrian

0 Kudos
Message 6 of 7
(3,174 Views)

I like reading/writing XML files for clusters.  In fact that is the format I use to save/load my user settings.  Just bundle everything you need to save into a cluster and write it to XML.  Read from XML, unbundle and you are on your way.  I've even come across some pretty slick VIs people have written to save all the properties of controls in a similar fasion.

 

I like the XML format because I can open it up in a text editor and understand the content.

 

The only pit fall is if I make changes to a cluster I make it complicated to read old XML files (since the data structure is now slightly different).  I remember someone had written a read anything/write anything wrapper for the XML file handlers that would magically adapt to changes in your clusters.  I haven't used them, yet, though.

0 Kudos
Message 7 of 7
(3,169 Views)