I want to add the perimeter in so it checks the perimeter of each floor. but when I do it calculates the perimeter value for the loops a and b instead of just the space on b b

조회 수: 2 (최근 30일)
floors=input('Please enter the number of floors in this building: '); while floors<1; disp(err); floors=input('Please enter the number of floors: '); end for a=1:1:floors spaces(a)=input(['Enter number of spaces on floor ',num2str(a),': ']); for b=1:1:spaces(a)
width(a,b)=input(['Please enter width of space ',num2str(b),' on floor ',num2str(a),': ']);
height(a,b)=input(['Please enter height of space ',num2str(b),' on floor ',num2str(a),': ']);
depth(a,b)=input(['Please enter depth of space ',num2str(b),' on floor ',num2str(a),': ']);
residentialRoom=questdlg('Is this space residential?', 'Residential?','Yes','No','No');
switch residentialRoom
case 'Yes'
residential=residential+1;
otherwise
officeRoom=questdlg('Is this space an office?', 'Office?','Yes','No','No');
switch officeRoom
case 'Yes'
office=office+1;
otherwise
educationRoom=questdlg('Is this space a educational?', 'Education?','Yes','No','No');
switch educationRoom
case 'Yes'
education=education+1;
otherwise
toiletRoom=questdlg('Is this space a toilet?', 'Toilet?','Yes','No','No');
switch toiletRoom
case 'Yes'
toilet=toilet+1;
otherwise
storage=storage+1;
end
end
end
end
X(a,b)=input(['Please enter x coordinate of space ',num2str(b),' on floor ',num2str(a),': ']);
Y(a,b)=input(['Please enter y coordinate of space ',num2str(b),' on floor ',num2str(a),': ']);
end
end
while spaces<=0
disp(err)
spaces(a)=input(['Enter number of spaces on floor ',num2str(a),': ']);
end
for b=1:1:spaces
rectangle('Position',[X(a,b),Y(a,b),width(a,b),depth(a,b)]);
end
save('floorplan.mat') load("floorplan.mat")

채택된 답변

LeoAiE
LeoAiE 2023년 4월 26일
If you want to calculate the perimeter for each space on each floor, you can add the perimeter calculation inside the nested loop for 'b'.
floors = input('Please enter the number of floors in this building: ');
err = 'Invalid input. Please enter a positive integer.';
while floors < 1
disp(err);
floors = input('Please enter the number of floors: ');
end
residential = 0;
office = 0;
education = 0;
toilet = 0;
storage = 0;
figure;
hold on;
for a = 1:1:floors
spaces(a) = input(['Enter number of spaces on floor ', num2str(a), ': ']);
for b = 1:1:spaces(a)
width(a, b) = input(['Please enter width of space ', num2str(b), ' on floor ', num2str(a), ': ']);
height(a, b) = input(['Please enter height of space ', num2str(b), ' on floor ', num2str(a), ': ']);
depth(a, b) = input(['Please enter depth of space ', num2str(b), ' on floor ', num2str(a), ': ']);
perimeter(a, b) = 2 * (width(a, b) + depth(a, b));
% Your room type calculations...
% ...
X(a, b) = input(['Please enter x coordinate of space ', num2str(b), ' on floor ', num2str(a), ': ']);
Y(a, b) = input(['Please enter y coordinate of space ', num2str(b), ' on floor ', num2str(a), ': ']);
end
end
% Plot rectangles
for a = 1:1:floors
for b = 1:1:spaces(a)
rectangle('Position', [X(a, b), Y(a, b), width(a, b), depth(a, b)]);
end
end
hold off;
save('floorplan.mat');
load("floorplan.mat");
  댓글 수: 3
LeoAiE
LeoAiE 2023년 4월 27일
I assume that you want to calculate the perimeter of each space and display it in the command window.
floors = input('Please enter the number of floors in this building: ');
while floors < 1
disp(err);
floors = input('Please enter the number of floors: ');
end
for a = 1:1:floors
spaces(a) = input(['Enter number of spaces on floor ', num2str(a), ': ']);
for b = 1:1:spaces(a)
width(a, b) = input(['Please enter width of space ', num2str(b), ' on floor ', num2str(a), ': ']);
height(a, b) = input(['Please enter height of space ', num2str(b), ' on floor ', num2str(a), ': ']);
depth(a, b) = input(['Please enter depth of space ', num2str(b), ' on floor ', num2str(a), ': ']);
% Calculate perimeter
perimeter(a, b) = 2 * (width(a, b) + depth(a, b));
% Display perimeter
fprintf('Perimeter of space %d on floor %d: %.2f\n', b, a, perimeter(a, b));
% Your other code for residential, office, etc. goes here
X(a, b) = input(['Please enter x coordinate of space ', num2str(b), ' on floor ', num2str(a), ': ']);
Y(a, b) = input(['Please enter y coordinate of space ', num2str(b), ' on floor ', num2str(a), ': ']);
end
end
% Your other code for drawing rectangles and saving/loading files goes here

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by