MATLAB: How to make sure variables aren’t overwritten in loops

for looptablevariable

I need to create a program that can document info on various floors which that can be later used to find out certain info on that floor such as plot a floor plan using coords or tell me how many rooms on whichever floor. However the variables keep getting overwritting the previous loops variables. This is the code I've got so far which is still a WIP for main features.
answerFloor=inputdlg('Enter','Number of Floors');
numberOfFloors=str2double(answerFloor{1});
if numberOfFloors<=0
disp('Invalid');
return
end
numberOfSpaces=zeros(1,numberOfFloors);
spaceX={1,numberOfSpaces};
spaceY={1,numberOfSpaces};
spaceZ={1,numberOfSpaces};
X={1,numberOfSpaces};
Y={1,numberOfSpaces};
for i=1:1:numberOfFloors
answerSpaces=inputdlg('Enter','Number of Spaces');
numberOfSpaces=str2double(answerSpaces{1});
for n=1:1:numberOfSpaces
list = {'Residential','Office','Education','Toilet','Storage'};
[indx,tf] = listdlg('ListString',list);
spaceType=[indx,tf];
answerSpaceX=inputdlg('Enter','Width of Space (m)');
answerSpaceY=inputdlg('Enter','Height of Space (m)');
answerSpaceZ=inputdlg('Enter','Depth of Space (m)');
spaceX(n)=str2double(answerSpaceX{1});
spaceY(n)=str2double(answerSpaceY{1});
spaceZ(n)=str2double(answerSpaceZ{1});
answerX=inputdlg('Enter','X Co-ordinate on floor (m)');
answerY=inputdlg('Enter','Y Co-ordinate on floor (m)');
X(n)=str2double(answerX{1});
Y(n)=str2double(answerY{1});
end
end

Best Answer

I suggest you load up rows in a table. See documentation for the table() function.