Using the Save command to save a logical mask

조회 수: 15 (최근 30일)
Aaron Smith
Aaron Smith 2017년 8월 9일
편집: Stephen23 2017년 8월 9일
I am attempting to use the Matlab save command to save a logical mask as a .mat file. The difficulty arises when I attempt to specify a path to save the file in. I need to be able to save the mask in a specific folder. I have tried multiple incarnations of this code:
handles = guidata(hObject);
Folder = uigetdir('C:\Users\c13459232\Documents\MATLAB\Completed code thus far\Mask');
filename = 'Mask_01.mat';
%handles.mask = mask;
save([Folder filename '.mat'], 'handles.mask');
guidata(hObject, handles);
handles.mask is the logical mask itself, created in another callback. I attempted to use the command form of save, I also tried simply saving handles.mask without any folder specified. The main error that occurs is Argument must contain a string but Matlab also does not recognize the mask with the error Undefined function or variable 'mask' also occurring. Is there something glaring I am doing wrong here?
  댓글 수: 8
José-Luis
José-Luis 2017년 8월 9일
Emphasizing what Stephen said, please accept the answer that best solves your problem.
Stephen23
Stephen23 2017년 8월 9일
편집: Stephen23 2017년 8월 9일
" By making mask = handles.mask, why is mask not simply the mask that i created handles.mask to share in the previous callback?"
It is.
" I understand what you mean now, that the logical mask itself isn't a variable because it is a matrix with a large number of values so the apostrophes are not necessary"
Not at all. The fact you have a matrix of values is irrelevant. What is relevant is that handles.mask is, in itself, not a variable. A variable has a name and that name can be found in some workspace. Can you see handles.mask in the workspace? No, you cannot. You can see handles in the workspace though. This means that handles is a variable. And, as the save documentation clearly states, save requires the name of a variable in the workspace. Not the name of a field of structure, not the title of a figure, not your aunts name, or anything else. Just the name of a variable. Knowing what a variable is is a very basic MATLAB concept, covered in the introductory tutorials:
Who mentioned anything about "the apostrophes are not necessary" ? I certainly didn't write that, and I cannot see that written in the answer below.
PS: "please accept the answer that best solves your problem." and also for many of your previous questions. Most volunteers do not like the feeling of being treated as a disposable service.

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

답변 (1개)

José-Luis
José-Luis 2017년 8월 9일
data = handles.mask;
save('someFile.mat','data');

카테고리

Help CenterFile Exchange에서 Author Block Masks에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by