How to save one of the variable in workspace in .mat format?

161 views (last 30 days)
I want to save one of the variable(50*110 size) from matlab workspace in .mat file.I need to send this file to my professor as attachment so that he can use imtool on that variable to get a image. I tried with save command, but I ended up with shortcut file which did not open in my own computer and I also couldn't upload that one as attachment. Any help will be highly appreciated.

Answers (4)

Thomas
Thomas on 3 Jul 2012
a=rand(50,110); % create random data
save('output.mat','a') % save variable in the output.mat file
check to see if the output.mat is created and load it again
clear variables % clear variables from workspace
load('output.mat')
Now variable a should be back in workspace..

Image Analyst
Image Analyst on 3 Jul 2012
Edited: Image Analyst on 3 Jul 2012
I know you know how to attach files to an email, but that's not your problem. The problem is that when you save a .mat file, Windows thinks this is a "Microsoft Office Access Table Shortcut" and it doesn't show the file with the extension in Windows Explorer even though you told it to show all extensions (through folder options) and not to hide extensions. And the file shows up as a shortcut, as you said.
The Mathworks has a tech note on this:
unfortunately it only applies to Windows XP. Which version of Windows do you have?
To fix it for Windows 7,
  1. Click the Windows flag button,
  2. Type regedit in the Search Programs and Files" edit field
  3. Browse to field HKEY_CLASSES_ROOT\.mat\OpenWithProgids
  4. Note the name of the MATLAB KEY, for example MATLAB.mat.7.14.0
  5. Browse to field HKEY_CLASSES_ROOT\.mat\OpenWithProgids
  6. Double click the (Default) name.
  7. Type in the MATLAB name, for example MATLAB.mat.7.14.0, into the Value data field, and click OK
  8. Exit out of regedit
  9. Restart your computer, (unfortunately this is necessary to re-read the registry as restarting Windows Explorer is not enough).
Nonetheless, even if you don't fix how it's displayed, you can still send the file as an attachment to your email.
  4 Comments
Tom
Tom on 3 Jul 2012
would it be worth, for now, writing the variable to a txt or xls file, and having your professor import it?
Image Analyst
Image Analyst on 3 Jul 2012
That's not needed. Like I said, it's still the same file with the same contents regardless of what it looks like in Windows Explorer or what default program Windows XP decides to open it with when you double click on it. He can just send without any issues.

Sign in to comment.


Bibek
Bibek on 3 Jul 2012
Thanks, but I want this variable 'a' not to restore in my workspace but to send it as an attachment in the email so that 2nd person getting this email can get it in the same size(50 by 110) and he can play with that one. Any suggestion for that.
  2 Comments
Tom
Tom on 3 Jul 2012
what's stopping you from sending the saved .mat file with the one variable stored in it?
Thomas
Thomas on 3 Jul 2012
that is exactly what this does.. I just showed the load command to confirm that the variable a was stored in the output.mat file.. You can attach the output.mat file via email, but your professor need matlab to open the output.mat file.
He needs to run the
load('output.mat')
in his MATLAB after he receives the file to work on it..

Sign in to comment.


Krishna
Krishna on 19 Apr 2023
a=10
a = 10
save('input.mat','a')

Categories

Find more on Data Import and Export in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!