How can i store a .mat file into a variable?

12 views (last 30 days)
i want get the syntax to store a .mat file into a variable.

Accepted Answer

Walter Roberson
Walter Roberson on 21 Mar 2017
fid = fopen('YourMatFile.mat', 'r') ;
YourVariable = fread(fid, '*uint8').' ;
fclose(fid) ;
YourVariable is now a row vector of bytes that make up the mat file.
This kind of thing can be useful if you need to transmit a mat file over wireless or Ethernet, but otherwise has limited use.
.... But perhaps the answer you were looking for was just
YourVariable = load('YourMatFile.mat');
Stephen23 on 22 Apr 2020
@Kieran Graham: the recommended approach is to simply load into an output variable
S = load(...);
All of your variables will be fields in the scalar structure S, and are trivial to access.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by