MATLAB: How to ask the user of the project to name and save there work

university

Doing some work for uni, was wondering if anyone knew how to right some code in order for the user to be able to save the work then load it at a later stage. My work so far is below.
floor=input('Please Input The number of floors you wish to enter:');
space = [];
dim = [];
listcoordinates = [];
spaceList = {'Residential','Office','Education','Toilet','Storage'};
spaceType = {'Residential','Office','Education','Toilet','Storage'};
floorLevel = {};
for i = 0:1:floor-1
rooms=inputdlg(['How many spaces on floor ',num2str(i),'?: ']);
space(end + 1) = str2double(rooms);
end
for k=0:1:floor-1
msg = msgbox(['For floor ',num2str(k),','],'Floor');
uiwait(msg);
for i=0:1:space(k+1)-1
result1 = inputdlg({['Width of space ',num2str(i+1),': '],['Length of space ',num2str(i+1),': '],['Height of space ',num2str(i+1),': ']},'Dimensions');
dim{k+1}{1,i+1} = str2double(result1{1});
dim{k+1}{2,i+1} = str2double(result1{2});
dim{k+1}{3,i+1} = str2double(result1{3}); % Columns are spaces, rows are dimensions for width, height, length.
type = listdlg('ListString', spaceList,...
'SelectionMode', 'Single', 'PromptString', 'Select item', 'Initialvalue', 1,'Name', 'Make choice');
floorLevel{k+1}{i+1} = spaceType(type);
result2 = inputdlg({['x-coordinate of space ',num2str(i+1),': '],['y-coordinate of space ',num2str(i+1),': ']},'Coordinates');
listcoordinates{k+1}{1,i+1} = str2double(result2{1});
listcoordinates{k+1}{2,i+1} = str2double(result2{2});
end
end

Best Answer

Try save() and load():
% Get the name of the file that the user wants to save.
% Note, if you're saving an image you can use imsave() instead of uiputfile().
startingFolder = pwd; % Or userpath or wherever you want.
defaultFileName = fullfile(startingFolder, 'Building Variables.mat');
[baseFileName, folder] = uiputfile(defaultFileName, 'Specify a file');
if baseFileName == 0
% User clicked the Cancel button.

return;
end
fullFileName = fullfile(folder, baseFileName)
save(fullFileName, 'listcoordinates', 'result2', 'floorLevel', 'spacelist');
Then to recall:
% Have user browse for a file, from a specified "starting folder", IF you're not using a fixed name.
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = pwd; % or 'C:\wherever';
if ~isfolder(startingFolder)
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
s = load(fullFileName);
listcoordinates = s.listcoordinates;
results2 = s.result2;
floorLevel = s.floorLevel;
spacelist = s.spacelist;