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 中查找有关 Flight Instruments 的更多信息

标签

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by