03-25-2019 05:49 AM
I want to write a 2D array row-by-row in "Level 5 MAT-File Format"
Example 2D array:
123
456
789
3 write operations, 123, append 456, append, 789.
Note it's not a 1D array, I need to know afterwards that 123 was from event1, 456 from event2 etc.
So far, I've looked at Matio VIs in VIPM, the Matlab data plug-in and VIs posted by users in the forums. I want to know a route that works with minimal hassle. Can anyone confirm if row-by-row is possible? Would I be better to save as TDMS, then convert to .mat as a post processing step? It seems strange that people have been trying to save data to use in Matlab regularly for the past 15+ years, but there are no easily found VIs around for this purpose.
Solved! Go to Solution.
03-25-2019 08:01 AM
Instead of trying to adopt to (potentially changing) MatLab data formats, why not use a "universal" format? Two come to mind -- plain Ascii text, possibly "wrapped" in a Comma-separated-Value (.csv) formatting that LabVIEW supports and that Matlab should have no trouble reading (I don't recall whether Matlab includes a routine to "auto-parse" the .csv format, but that shouldn't be difficult) and "straight binary", but with the "array size" headers included (the default of the input "prepend array or string size", default T). There may be an "endian" problem, but you should be able to work this out easily, and if you go the binary route, you definitely need to know something about the data you are expecting.
Another extreme is to use a "self-documenting" format such as XML. But I'd suggest considering Text or Binary (one "verbose", but Human-friendly, the other "maximally terse", "machine-friendly", but potentially "human-hostile") first.
Bob Schor
03-25-2019 10:07 AM
this data format is often used in applications related to spectrometry
as far as I am concerned the Level 5 MAT-File is described by this protocol:
https://www.mathworks.com/help/pdf_doc/matlab/matfile_format.pdf
Take a look at the section "Level 5 MATLAB Array Data Element Formats"
03-25-2019 11:04 AM
@bmann2000 wrote:
It seems strange that people have been trying to save data to use in Matlab regularly for the past 15+ years, but there are no easily found VIs around for this purpose.
03-25-2019 11:13 AM
Mathworks do state the plug-in can be used for:
creating data sets within LabVIEW that can then be utilized within MATLAB® software
So Mathworks provide the VIs that write the Matlab file format. I suppose it does make sense, because then Matworks become responsible for providing new VIs if the format changes in the future.
Had anyone used the plug-in, and does it allow you to write a 2D array, line-at-a-time?
03-26-2019 04:20 AM
Hi Bmann,
The plug-in is a tool from NI to make files accessible to MATLAB® and is maintained by NI.
I think I have never seen a file IO tool which doesn't allow to append data to a file or channel. But I am still not able to see why your example data is a 2D array. Is the event1, event 2 etc. a second column which you need to write simultaneously?
The plug-in is channel based, thus a 2D array needs to be saved as multiple channels.
Generally I agree with Bob, that going down the ASCII/csv route might be easier if you don't want to spend the time understanding binary file formats.
Cheers,
03-28-2019 06:31 AM
The LabVIEW Matlab data plugin works, you need this link to get started with plugins.
http://www.ni.com/tutorial/11951/en/
I will create an accompanying .csv text header file with the index of each line start position.