I need to make a running total of the number of spaces but i cant figure out how?
    조회 수: 9 (최근 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개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!