필터 지우기
필터 지우기

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

조회 수: 114 (최근 30일)
Bibek
Bibek 2012년 7월 3일
답변: Krishna 2023년 4월 19일
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개)

Thomas
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..

Image Analyst
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,
  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
Tom
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
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
Bibek 2012년 7월 3일
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
Tom
Tom 2012년 7월 3일
what's stopping you from sending the saved .mat file with the one variable stored in it?
Thomas
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..

댓글을 달려면 로그인하십시오.


Krishna
Krishna 2023년 4월 19일
a=10
a = 10
save('input.mat','a')

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by