I want to get the byte array of a .mat file of a specific matrix. How can I do that?
I can save a matrix on disk by this command:
save('a.mat', 'a')
Now, I do not want to save the .mat file on disk. Instead, I want it in memory to send it over a network.
You could use a couple of undocumented functions (used internally by save
and load
) for serializing/deserializing data. This would allow you to encode your matrix a
into a byte stream the same way save
would when storing it in a .mat file:
byteStream = getByteStreamFromArray(a);
You can then send this byte stream data over a network and decode it on the receiving end like so:
a = getArrayFromByteStream(byteStream);
Well... if you want to send the binary content of a mat
file through a network, you have no choice but proceeding as follows:
Save your data to disk in mat
format:
save('a.mat','a');
Read the saved mat
file as a byte array:
fid = fopen('a.mat','r');
data = fread(fid);
Send the binary data through the network:
send_data(data);
If you want to go for a much more elaborate approach (I don't recommend it by the way), like digging into a mat
file in order to exctract data or building your own mat
file at runtime, this is a good starting point .
I don't think this is possible. But you could write the MAT file to a temporary directory (see tempdir
) and then open it as a binary file, read its contents back in memory as a uint8 array or something like that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.