MATLAB: How do i stop the array changing after every iteration of the loop

university

Greetings, my current problem is that my array 'width' values change after every iteration of my for loop, was wondering if anyone new knew how to fix this so i can add the vlaues to the array instead of them being replaced?
answera=inputdlg({'Please Input The number of floors you wish to enter:'},'Floors');
floor = str2num(answera{1});
for j = 1:1:floor
answerb=inputdlg(['How many rooms are on floor: ',num2str(j)]);
room=str2num(answerb{1});
end
width=[];
totalA=0;
totalB=0;
for k = 1:1:floor
msg = msgbox(['This is for floor: ',num2str(k)]);
uiwait(msg);
for i = 1:1:room
answerc=inputdlg(['What is the width of space',num2str(i)]);
width{1,i}=str2double(answerc{1});
totalA=totalA+width{1,i};
end
end

Best Answer

Replace width{1,i} with width{k,i}.
Your code is also not loading the number of rooms for the inner loop.