My code will not plot the rectangle, it says theres an issue I cant figure out where I am going wrong?

1 Ansicht (letzte 30 Tage)
My code has a loop for each floor which asks the number of residential spaces on the floor, for each space it then asks the width and length. Then it asks if the user would like to do a floorplan, if yes is selected its supposed to ask for an x and y coordinate then plot using the already given length and width however this last step does not work and I cant figure out why. It says the error is on the line starting with 'rectangle'.
for c = 1:1:sBuilding(n).bNoOfFloors
disp("--------------FLOOR "+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).office(i).length]);
axis ([0 1000 0 1000]);
hold on
end
end
end
end

Akzeptierte Antwort

Voss
Voss am 1 Mai 2022
I guess that "office":
rectangle('Position',[locationx locationy ...
sFloor(c).resident(i).width ...
sFloor(c).office(i).length]);
should be "resident":
rectangle('Position',[locationx locationy ...
sFloor(c).resident(i).width ...
sFloor(c).resident(i).length]);
(I'm not sure that will fix the error you ran into, since I don't know what the actual error was.)

Weitere Antworten (0)

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by