I need to make a running total of the number of spaces but i cant figure out how?

2 ビュー (過去 30 日間)
I have made a loop to go through each floor and ask the number of residential spaces on that floor then plot it. I now need to work out the total number of residential spaces (all floors considered) but I am not sure how to go about this.
for c = 1:1:sBuilding(n).bNoOfFloors
disp("--------------FLOOR "+c+" --------------")
subplot(sBuilding(n).bNoOfFloors,1,c);
title(sprintf('Floor %d',c));
sFloor(c).NoOfResidentialSpaces = input('Enter Number Of Residential spaces:');
if sFloor(c).NoOfResidentialSpaces > 0
for i = 1:1:sFloor(c).NoOfResidentialSpaces
sFloor(c).resident(i).width = input("Enter width of Residential room " +i+" on floor "+c+":");
sFloor(c).resident(i).length = input("Enter length of Residential room "+i+" on floor "+c+":");
choice1 = questdlg('Would you like to draw a floorplan?','question','yes','no','yes');
switch choice1
case 'no'
disp('No floorplan')
case 'yes'
locationx=input("Please specify bottom left corner X coordinate of residential room "+i+" on floor "+c+":");
locationy=input("Please specify bottom left corner Y coordinate of residential room "+i+" on floor "+c+":");
rectangle('Position',[locationx locationy sFloor(c).resident(i).width sFloor(c).resident(i).length]);
axis ([0 100 0 100]);
hold on
end
end
end
end

採用された回答

Monica Roberts
Monica Roberts 2022 年 5 月 3 日
You could create a sum as you loop through:
roomtotal = 0;
for c = 1:1:sBuilding(n).bNoOfFloors
disp("--------------FLOOR "+c+" --------------")
subplot(sBuilding(n).bNoOfFloors,1,c);
title(sprintf('Floor %d',c));
floortotal = input('Enter Number Of Residential spaces:');
sFloor(c).NoOfResidentialSpaces = floortotal;
roomtotal = roomtotal + floortotal;
if sFloor(c).NoOfResidentialSpaces > 0
for i = 1:1:sFloor(c).NoOfResidentialSpaces
%%ETC

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by