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

1 vue (au cours des 30 derniers jours)
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

Réponse acceptée

Monica Roberts
Monica Roberts le 3 Mai 2022
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

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by