I need to make a running total of the number of spaces but i cant figure out how?
1 次查看(过去 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
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!