10-27-2016 01:36 PM
I have two different types of binary file that contains a cluster and an array of the same cluster that I can R/W fine with LabVIEW.
Matlab has an issue reading and requires me to input field name, type for each field, number of bytes, array size information...etc
Details on the file content in the attachment.
How can I define each element in my cluster data type so that Matlab can read my file or if there is any other method of making this data transfer possible that you would recommend?
Thanks
Solved! Go to Solution.
10-27-2016 04:16 PM
This is yet another example of the value to the Original Poster of attaching code (an executable VI or an executable LabVIEW Snippet) to help us help you. It would be relatively easy to write a description of the Matlab format had you provided such a code, as we could generate an example for ourselves and test/verify that what we proposed was correct. Oh, well.
But you largely already know the answer, as you've shown us a picture of your Cluster and also what Matlab is expecting. The tricky parts is knowing how arrays are saved in Binary Files (any why it is important that we see the code you use to write the file -- are you includiing the Array Size, specifically, in your Write command?), as well as being able to interpret the LabVIEW TimeStamp (saved as a 128-bit "strange fraction" format).
Bob Schor
10-27-2016
05:02 PM
- last edited on
01-08-2025
02:30 PM
by
Content Cleaner
Yes, I need to tell Matlab what it is reading. LabVIEW reads fine as it already knows its own data type as being the writer of the binary file. But talking to any software outside of the LabVIEW would require a similar understanding of the record structure to read the binary file. Some of the data type conversions in binary format are abstract. (timestamp,array structures...)
I found someting on timestamp datatype information: https://www.ni.com/en/support/documentation/supplemental/08/labview-timestamp-overview.html
I would like to learn how the arrays(1D,2D), strings are being saved into binary file in LabVIEW to be able to read the file from other platforms.
I am not sure if NI is forcoming with this information but wondering if there is any NI article on how that binary data conversion been done and saved with any elements that I can possibly have within my LabVIEW cluster data type?
10-27-2016 06:11 PM
Again, some of that you control by how you wire the Write Binary Data function (which is why you need to post your code. A lot of this information is readily available, and we are happy to help you, but we need to know what you tell LabVIEW to do (which we can only do by seeing the code you used) in order to say, for example, if there is array/string size information as part of the file. We are trying to help you, but you need to help us to help you ...
Bob Schor
10-27-2016 06:57 PM
Check out https://sourceforge.net/projects/matio-labview/?source=recommended
This is to make native Matlab files in LabVIEW. Or You can also use of fopen in Matlab and parse the file yourself. Note in your picture you are adding a length to the cluster, make this false, it may make parsing it easier. this is the Boolean input on top of the write file vi. Sorry for the typos on a iPad.
mcduff
10-27-2016 07:03 PM - edited 10-27-2016 07:07 PM
Bob, Here is my Binary Handler VI I used to for my R/W operations. 2D array sizes within the cluster and 1D array size of the main data cluster array for array type binary file depends on user selection in each operation.
I would like to be able to read the binary files with the given format from Matlab generated by the attached VI.
You can also find sample LabVIEW generated .bin files for both types in the attachment.
12-01-2016 01:40 PM
Anyone has any idea on how to decode the typedef in my previous post in a non Labview environment?
I post my binary file IO vi that contains my typedef into my previous post. LabVIEW prepends array and string size to the binary file by default and represents some of the data types in its own way. I would like to learn how labview binary file byte allocation works when you pass a cluster that contains strings,timestamps.2D arrays and some numeric values as seen in my post above. Any ideas?
12-01-2016 09:02 PM - edited 12-01-2016 09:16 PM
Sorry, I missed your earlier post. Let me help you with array.bin, as single.bin will be one step easier. This will not be a "complete" LabVIEW answer, as there are some types that aren't covered here, but here goes:
So if you are really interested in parsing this file, you need to know the "file composition" (provided nicely by the ArrayIn description you provided on your JPG file. Whenever you see an Array, you know you need to read a 4-byte I32 to get the Array size(s), then read that many Array Elements. If the Element is a Cluster (as is the case here), you need to read each element of the Cluster, which (in turn) may contain Strings (with a prepended 4-byte length) or Arrays (with size(s) + elements).
Look up the definition of TimeStamp. You'll see that it really is a 128-bit integer representing the number of ticks of a very fast clock (I forget the clock rate, but it is >1MHz) since 1 Jan 1904 UTC.
Hope this is helpful.
Bob Schor
P.S. -- I'm not (now) 100% certain that I've stated the TimeStamp format correctly. It is a bit messy ...
12-01-2016
10:42 PM
- last edited on
01-08-2025
02:30 PM
by
Content Cleaner
@Bob_Schor wrote:
P.S. -- I'm not (now) 100% certain that I've stated the TimeStamp format correctly. It is a bit messy ...
Here is a document that describes the timestamp better. https://www.ni.com/en/support/documentation/supplemental/08/labview-timestamp-overview.html
The first 8 bytes represent seconds since 1/1/1904 midnight GMT. The second 8 bytes is a 2^64 bit fraction of a second.
12-05-2016 05:53 PM
Thx very much for your detailed reply Bob. That is exactly what I needed. One more question:
One thing that I included my cluster in a later version is "path" data type that I could not understand how binary represantation is handled. I ended up converting path to string so that I can decode it like a string to resolve the issue. Do you know how path type being flattened into binary string format?