Jump to content

A Mat-file IO Library


Recommended Posts

Jim,

The VI is working well, I just had one last question. I am having difficultly figuring out how to name the elements of my clusters. When I sent you the VI I had labeled them, but looking at the difference (names seem to have black borders around them) between my version and yours I noticed that there is a qualitative difference between naming a field and labeling it. If you could tell me how to access that property of a field I would appreciate it. As always thank you very much for your help.

Regards,

-Jon

Link to comment

Jim,

The VI is working well, I just had one last question. I am having difficultly figuring out how to name the elements of my clusters. When I sent you the VI I had labeled them, but looking at the difference (names seem to have black borders around them) between my version and yours I noticed that there is a qualitative difference between naming a field and labeling it. If you could tell me how to access that property of a field I would appreciate it. As always thank you very much for your help.

Regards,

-Jon

Hi Jon,

I think they're the same. I edited your VI using LabVIEW 8.2.1, later versions of LabVIEW seem to have a default label appearance of having a transparent border. Check out the LabVIEW help for details on changing the color of objects.

Jim

Link to comment

Jim,

With the help you provided me I was able to build most of the VI that I need to structure my data as I gather it. However I am having an issue creating arrays of clusters. When I try to do this, I get an error message "Error 1026 occurred at Close Reference in level5.lvlib:Append Data Element (Anything).vi:3->level5.lvlib:Append Data Element (Anything).vi:2->data_struct.vi." That is, the error occurs not with opening the file in Matlab, but in writing it to the file. I noticed someone else (Dominik) mentioned also that he was unable to create arrays of clusters, but from the forum discussion it seemed like the issue was resolved by naming the variables (also his issue seemed more on the end of opening the file in Matlab). I made sure my variables are named, and I even ran the program on a newer version of LabVIEW that has the MatIO library installed to make sure it wasnt the computer, but as long as I had an array of structures in my VI i got the error ( when I deleted this section of code from the block diagram I had no issues). I read from the National Instruments web page that creating an array of clusters is allowed in LabVIEW, so I know I'm not breaking any rules on that front. The error message causes me to suspect that the issue might have something to do with the library and not so much my code, but it would be great if you could take a look at it (see attached VI). Thank you for your time, and I apologize if the error stems from something trivial.

-Jon

data_struct.vi

Link to comment

Hi Jon,

The error was a bug, and has been fixed in version 0.1-8.

However, another problem is that you are trying to write an empty cluster array to a mat-file. I don't think this has a MATLAB equivalent. Clusters are like MATLAB structures, and arrays of clusters are like MATLAB cell arrays; so an empty cluster array is like an empty MATLAB cell array of structure. I haven't been able to recreate this in MATLAB.

Now that the error has been fixed, the library will write an empty cell array to the mat-file when you tell it to write an empty cluster array.

Thanks for helping to improve the library. Let me know if you have any other questions.

Jim

Link to comment

Hi Jon,

The error was a bug, and has been fixed in version 0.1-8.

However, another problem is that you are trying to write an empty cluster array to a mat-file. I don't think this has a MATLAB equivalent. Clusters are like MATLAB structures, and arrays of clusters are like MATLAB cell arrays; so an empty cluster array is like an empty MATLAB cell array of structure. I haven't been able to recreate this in MATLAB.

Now that the error has been fixed, the library will write an empty cell array to the mat-file when you tell it to write an empty cluster array.

Thanks for helping to improve the library. Let me know if you have any other questions.

Jim

Hey Jim,

Thanks again for you're help. I'm trying to create an array of clusters that dynamically changes size as data is collected. Unfortunately, I've been having difficulty doing this because in order to have the variables named for Matlab, I need to use the "insert into array" block which means that I need an array to insert the blocks into (otherwise the program won't run). The only way I have been able to do this is by using an Array constant. In doing so, I am required to initialize every element in the array, which can be very tedious for large sets of data. I attached a sample VI that might give you some idea of what I'm trying to do. As a simplified model I basically want to create an array of clusters, where each cluster contains a string and a value. In the VI, I don't bother changing the string value (its just there to lend to the cluster) but I would like the element in each cluster to reflect the value of iteration. I have some background in programming ( a semester in C and two in Java, with the Java being more recent) so if you need to get a little technical i should be able to understand. Additionally, I realize that clusters are meant to reflect C's structures, and in C you can't dynamically change the size of an array, but I've seen that it can be done in LabVIEW. Clearly an array constant will have a constant size, so I guess if you can figure a way around this I would love to know. Thanks again for all of your help, I would not have been able to get this far without you.

Regards,

-Jon

Link to comment
  • 3 weeks later...

Hey Jim,

I'm trying to figure out how to append data to an already existing file. I tried the different settings on on the"file open/create/replace" but I have not had any luck. It seems that they way it stores the data overwrites the existing data from before. I have tried to fix this using suggestions posted on the web that implement "set file at position" but this has not worked for me. Currently the way I have my VI set up is that the data is stored in a cluster array that increases in size with every iteration and only after the program stops is all of the data saved. While this works sometimes, I have encountered times where an error has occurred in stopping the program (time out issue, etc) and all of the data was lost. Does your MatIO library have anything to allow for appending or have you not worked that in yet.

Thanks,

-Jon

Link to comment

Hello again,

In the snippet below, I am trying to read a file without knowing what data types are in it. I'm using Whos to get the variables cluster and then calling the appropriate library function for each variable type.

I've tried two approaches - reading using 'Anything' and reading using the right type but in both cases I end up with data in a format that is difficult to use - arrays of variants or needing to build a cluster at runtime etc.

Is there a better/correct way that I am missing please?

Thank you,

Martin

post-13935-098789300 1278843516_thumb.pn

Link to comment
  • 3 weeks later...

All,

I have been working with the matio library (0.1.8) and it works fine! With some creativity in using the library one can save and read just about anything. I did however catch a bug in the List Variables (mat string).vi (the whos vi). I was trying to read a generic mat file which did not contain miCOMPRESSED data, but standard miMATRIX data. When the whos VI was used only 1 variable was listed, the first in the file. The file itself contained 19 variables.

After some investigation from my part I discovered that in the vi the "remaining string" was only passed to the second iteration of the while loop listing the variables if the datatype was miCOMPRESSED. The other option in the case selector was _invalid. The latter was also the default case. I took the liberty to change the case selector in such a way that the _invalid is no longer the default case. I added the miMATRIX datatype and applied the "split string" there too, like in the miCOMPRESSED case. I made this the default case. After this minor change all variables (1D double arrays, miMATRIX) are recognized perfectly. I want to stress that I have not tested it with any other datatypes. I just found out today. So please use caution.

@cookjr, I hope you can use my feedback in the next version of the matio library. I really appreciate your work! It helped me a lot. Also because I hate to write Wrapper C++ DLL's to interface with the libmat.dll to be able to use LabView writing and reading mat files.

I have attached the VI as well as a code snippet.

Thanks. René

post-17928-099871500 1280320731_thumb.pn

List Variables (mat string) v2.vi

Link to comment

Hi Jim,

does the library support reading of structures created with MATLAB.

Currently i'm having trouble with this.

In the example I try to read a simple Matlab struct

contained in d.mat, having one field "a" (scalar double) and one field

"b" (vector double).

Apparently there is something wrong with the type input (test_cluster.ctl)

on the matio read VI. The attached example fails with an error message

complaining about a connector pane mismatch.

Any help would be appreciated

Best

Dominik

post-16481-094096900 1280407755_thumb.pn

post-16481-019102300 1280407751_thumb.pn

test_matio_read_struct.vi

test_cluster.ctl

d.mat.zip

Link to comment
  • 1 month later...
  • 2 months later...

post-18561-0-48605800-1291750737_thumb.p

Hi Pieter,

unfortunately no. I didn't investigate this further.

Best

Dominik

Hi Jim, Pieter or Dominik:

I am fighting the same problem that Pieter and Dominik are finding: Error 1031 in the ExtractDataElement.vi. I'm running Labview 2009 and modified Jim's write Structure.vi example to add the routines to read the data file and put the mat file data into a structure. I probably don't have something set up correctly. Thanks Jim for all your hard work and making this available.

Thanks

Link to comment
  • 1 month later...
  • 11 months later...

post-18561-0-48605800-1291750737_thumb.p

Hi Jim, Pieter or Dominik:

I am fighting the same problem that Pieter and Dominik are finding: Error 1031 in the ExtractDataElement.vi. I'm running Labview 2009 and modified Jim's write Structure.vi example to add the routines to read the data file and put the mat file data into a structure. I probably don't have something set up correctly. Thanks Jim for all your hard work and making this available.

Thanks

Hi for all

This solution worked for me...

Access the VI: Extract Data Element (Anything)

Select in Case structure: "cluster"

Delete: type specifier VI Refnum (for type only)

Create a new constant, click with right button (black circle in the picture), and in "Select VI Server Class->Browse" go to the addres: c:<address Labview>user.lib_matiolevel5PublicRead and select "Extract Data Element", and select the Extract Data Element (Anything).

Save the VI, and Done!!!

4j6ou8.jpg

Link to comment
  • 10 months later...
  • 3 years later...

Hey Jim,

I'm trying to figure out how to append data to an already existing file. I tried the different settings on on the"file open/create/replace" but I have not had any luck. It seems that they way it stores the data overwrites the existing data from before. I have tried to fix this using suggestions posted on the web that implement "set file at position" but this has not worked for me. Currently the way I have my VI set up is that the data is stored in a cluster array that increases in size with every iteration and only after the program stops is all of the data saved. While this works sometimes, I have encountered times where an error has occurred in stopping the program (time out issue, etc) and all of the data was lost. Does your MatIO library have anything to allow for appending or have you not worked that in yet.

Thanks,

-Jon

 

Hi,

 

first of all, thanks for the great VI's, it was just what i was looking for and its working great so far.

I also do have a solution for appending to an existing mat file. In my case, I have written a program to configure an oscilloscope and get waveforms from. Therefore, I have some data which are header information, like the actual sampling rate or attenuation etc. and on the other hand the waveform itself. I have one VI collection the header informations and one grabbing the waveform data and both are writing consecutively to the same file. I managed to do this with this matio, if you take care of the following:

1. Only the first Vi to write to the mat file is generating the initial string with the "WriteHeader.Vi" from matio and passing it to "writeData.Vi".

2. Every other Vi following just use the WirteData.Vi with the initial string input unwired.

3. Set the file position always to the end before writing to the binary file.

Maybe 4. I also ensured a proper logic when reopening the file. I.e. the first time, I use the "create" option with "Open File" and after that the "open only" Option, but I'm not sure weather this has a strong influence. I guess it will "just" give an error, if you try to open an non-existing file et vice versa.

 

So considering these 3 points, I was able to append to an existing file as described above.

Have fun and thanks again for these VI's

 

Bastlwastl

Link to comment
  • 2 months later...

Hi to all,

 

I tried to use matio libraries in order to save directly in mat file data that acquired from DAC card. The file that occurs cannot be opened from Matlab as corrupted.

What is the issue, and the file is corrupted?


I attach also the vi and mat files.

 

Thank you in advance.

Kind regards,

Thanassis

dac2mat.zip

Link to comment
  • 1 year later...

It seems the two functions used are uncompress, and compress, given a string input, and generating a string output.  I'm unsure of if or how the LabVIEW native zip functions could be used in place of these but if you can do that this will be more multi-platform.  Also how in the heck did I miss this toolkit all my life?  Very cool.

Link to comment
  • 3 years later...
On 3/18/2010 at 2:12 PM, cookjr said:

Try the attached VI.

There is some documentation here, but it only has info on writing to a file right now. :(

If anyone wants to help out, they're welcome to add to it.

Jim

read_test.mat.viUnavailable

Hey Jim,

i have the same issue, i really would like to read some .mat data from matlab. I'm not even able to open a stingle string or an integer.
Your attached read_tesd.mat.vi data is already unaviable.
Could you help me out please?

 

Thanks
Máté

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.