12-17-2009 11:11 AM
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
12-17-2009 12:47 PM
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?
12-18-2009 05:35 AM
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
12-18-2009 09:36 AM
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!
12-18-2009 09:38 AM
There are many ways to save clusters to file:
12-18-2009 12:48 PM
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
12-18-2009 01:06 PM
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.