Workspace not saving - just disappearing!

7 views (last 30 days)
10B
10B on 28 Sep 2015
Commented: 10B on 28 Sep 2015
Hello Community,
I dont understand what is happening here. I am using a line of code to save my workspace - however what happens is the saved workspace doesnt get created, the dialogue box just disappears and nothing is saved. Code as:
[file,path] = uiputfile('*.mat','Save Workspace As');
so when I call this and fill in the filename in the dialogue box - nothing gets saved at all. Variables 'file' and 'path' are created and are added to the workspace, but a copy of all the variables contained in the workspace under a '.mat' file is not created or added to the current parent folder.
Any ideas as to whats going on here?
Regards,
10B.

Accepted Answer

Star Strider
Star Strider on 28 Sep 2015
Edited: Star Strider on 28 Sep 2015
From the documentation:
  • Note: Successful execution of uiputfile does not create a file; it only returns the name of a new or existing file that you designate.
Add these lines after the uiputfile call:
pf = fullfile(path, file); % Combines ‘path’ & ‘file’
save(pf); % Saves Workspace
(I did not test this code, but it should work.)
  7 Comments
Image Analyst
Image Analyst on 28 Sep 2015
Well unless you have a backup copy of the code, I think it will remain a mystery. I really think that the code must be different between the two because otherwise it should work the same. I see no reason why it should work fine, and then without having made any changes whatsoever, suddenly quit working.
Each time you enter a new function you are in a new scope, and this new scope has a different workspace. There is not just one workspace - there are lots that come into existence and vanish as you enter and leave functions. Each function has it's own scope, and then there is the base workspace. If you're in a script, then you can see a special workspace called "the base workspace", but once you enter a function, you are in the scope of that function and you see that only that function's workspace - no others. You don't see the base workspace any longer unless you make some special function calls to let you see it. But if you just call save() from inside a function, you will save that functions collection of private variables, not the variables in the workspace of the thing that called the function (which may be the base workspace if you called it from a script, or the parent function's workspace if you called the function from another function. There are some cases where a child function can see the parent/calling function's variables and you can look into that if you want.
Does that explain it better? Actually it's much like any other programming language in that respect.
10B
10B on 28 Sep 2015
Hello Image Analyst,
Yes, thanks for the explanation. I hadn't thought of that as a process - but it makes sense.
I had made changes to the script yes, but not in a way that effected this part of the code - or at least so I thought!
Unfortunately, I overwrote the code so I can't go back to confirm the changes, but there you go, another lesson learnt for next time.
Regards,
10B.

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!