Jhow88 Posted June 16, 2010 Report Share Posted June 16, 2010 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 Quote Link to comment
cookjr Posted June 16, 2010 Author Report Share Posted June 16, 2010 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 Quote Link to comment
Jhow88 Posted June 16, 2010 Report Share Posted June 16, 2010 Jim, Thanks again for your speedy replies and all of the help you provided. -Jon Quote Link to comment
Jhow88 Posted June 16, 2010 Report Share Posted June 16, 2010 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 Quote Link to comment
cookjr Posted June 17, 2010 Author Report Share Posted June 17, 2010 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 Quote Link to comment
Jhow88 Posted June 18, 2010 Report Share Posted June 18, 2010 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 Quote Link to comment
cookjr Posted June 18, 2010 Author Report Share Posted June 18, 2010 Hi Jon, Using the build array primitive is not the most efficient way to do it, but this works. Jim example.vi Quote Link to comment
Jhow88 Posted June 18, 2010 Report Share Posted June 18, 2010 Once again, incredible instructions and help. You are a scholar and a gentleman, thanks again. -Jon Quote Link to comment
Jhow88 Posted July 7, 2010 Report Share Posted July 7, 2010 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 Quote Link to comment
MartinMcD Posted July 10, 2010 Report Share Posted July 10, 2010 Hello there, This library sounds great & exactly what I'm looking for. However I'm struggling to get started at reading a mat file. Does anyone have an example that they'd be able to share with me please? Thanks very much, Martin Quote Link to comment
MartinMcD Posted July 11, 2010 Report Share Posted July 11, 2010 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 Quote Link to comment
Rene Posted July 28, 2010 Report Share Posted July 28, 2010 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é List Variables (mat string) v2.vi Quote Link to comment
kinimod Posted July 29, 2010 Report Share Posted July 29, 2010 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 test_matio_read_struct.vi test_cluster.ctl d.mat.zip Quote Link to comment
pspl Posted September 9, 2010 Report Share Posted September 9, 2010 Hi Dominik did you solve your problem yet? I'm struggling with the exact same problem of this otherwise excellent llb. pieter Quote Link to comment
kinimod Posted September 10, 2010 Report Share Posted September 10, 2010 (edited) Hi Pieter, unfortunately no. I didn't investigate this further. Best Dominik Hi Dominik did you solve your problem yet? I'm struggling with the exact same problem of this otherwise excellent llb. pieter Edited September 10, 2010 by kinimod Quote Link to comment
mmckenna Posted December 7, 2010 Report Share Posted December 7, 2010 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 Quote Link to comment
TruthWarrior17 Posted January 12, 2011 Report Share Posted January 12, 2011 MATLAB .mat files are memory intensive. I am getting LabVIEW memory errors when I try to load any of my real .mat files in. Have any of you tackled this issue? Quote Link to comment
leard Posted January 6, 2012 Report Share Posted January 6, 2012 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!!! Quote Link to comment
gary1wang Posted November 12, 2012 Report Share Posted November 12, 2012 Hi guys I have some problem on reading the .mat file using the mat-file io library. can some one give me some advise. I made the a matlab file with several arrays with title. After i read back it only give me some symbols. one 2D array and four 1 Darray. Thanks gary The vi and mat file are in the attatchment vi and mat file.zip Quote Link to comment
bastlwastl Posted December 16, 2015 Report Share Posted December 16, 2015 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 Quote Link to comment
ampimis Posted March 8, 2016 Report Share Posted March 8, 2016 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 Quote Link to comment
Zeus Knight Posted October 1, 2017 Report Share Posted October 1, 2017 Hi to everybody, I installed the Matio library but I wasn't able to test it, because it use the openg zip package (e.g. lzip deflate) that only run on labview 32 bit, and I have a 64 bit version of LabVIEW. Any hint on a workaround? ZeusKnight Quote Link to comment
hooovahh Posted October 2, 2017 Report Share Posted October 2, 2017 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. Quote Link to comment
smithd Posted October 2, 2017 Report Share Posted October 2, 2017 may or may not be sufficient, but since mat files are just hdf5, this library http://h5labview.sourceforge.net has an example for reading and writing the special matlab metadata. 1 Quote Link to comment
Máté Posted October 22, 2020 Report Share Posted October 22, 2020 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é Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.