How to save one of the variable in workspace in .mat format?
90 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(4 个)
Thomas
2012-7-3
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..
0 个评论
Image Analyst
2012-7-3
编辑:Image Analyst
2012-7-3
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,
- Click the Windows flag button,
- Type regedit in the Search Programs and Files" edit field
- Browse to field HKEY_CLASSES_ROOT\.mat\OpenWithProgids
- Note the name of the MATLAB KEY, for example MATLAB.mat.7.14.0
- Browse to field HKEY_CLASSES_ROOT\.mat\OpenWithProgids
- Double click the (Default) name.
- Type in the MATLAB name, for example MATLAB.mat.7.14.0, into the Value data field, and click OK
- Exit out of regedit
- 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 个评论
Tom
2012-7-3
would it be worth, for now, writing the variable to a txt or xls file, and having your professor import it?
Image Analyst
2012-7-3
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.
Bibek
2012-7-3
2 个评论
Tom
2012-7-3
what's stopping you from sending the saved .mat file with the one variable stored in it?
Thomas
2012-7-3
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..
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Export 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!