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

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.

回答(4 个)

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..
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 个评论

Thanks. I have XP but I could not complete step 5: From the "Associated File Type" list, choose "MATLAB MAT - File"; because I could not get the option, "MATLAB MAT - File".I found other associated file types like matlab code, matlab data, matlab figure. But when i go any one of these three, I ended up getting "Microsoft Office Access Table Shortcut" and got a error message ' can not resolve this link. this file may not be a shortcut' when I was trying to attach this file. This really turns out to be puzzling.
I don't have XP anymore so I can't walk you through it. Perhaps you can ask your computer support person or call MATLAB. I would think that you could just specify what program to use and browse to find MATLAB.EXE and that should work.
would it be worth, for now, writing the variable to a txt or xls file, and having your professor import it?
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.

请先登录,再进行评论。

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 个评论

what's stopping you from sending the saved .mat file with the one variable stored in it?
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..

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Import, Export, and Conversion 的更多信息

提问:

2012-7-3

回答:

2023-4-19

Community Treasure Hunt

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

Start Hunting!

Translated by