Clear Filters
Clear Filters

Code does not plot my values above a certain z coordinate

1 view (last 30 days)
Hi, i'm very new to matlab and have become stuck with plotting a 3d rectangle above a certain patch level.
The aim of my code is to create a 3D spacial model depending on what the user inputs. This includes them being able to specify the number, size (width and length) and heights of certain floors, followed by the number, size (width and length), height and where they wish to plot spaces using coordinates.
The spaces seem to just become 2D after the second floor has been plotted.
I hope someone understands this
Thank you for any help in advance :)
floorlengths=zeros(1,numbfloors);
floorwidths=zeros(1,numbfloors);
floorheights=zeros(1,numbfloors);
mainlooptotal=1;
while mainlooptotal<=numbfloors
% then in this one i can reference the data behind in the arrays
for i=1:1:numbfloors
floorlengths(i)=input(['Enter floor:',num2str(mainlooptotal), ' length: ']);
if i>1
while(floorlengths(i)>floorlengths(i-1))
floorlengths(i)=input(['Floor length',num2str(floorlengths(i)),' is more than the floor bellow ',num2str(floorlengths(i-1)),' Please enter floor:',num2str(mainlooptotal), ' length']);
end
elseif floorlengths(i)<0
floorlengths(i)=input('Lengths have to be >0. Please enter length!');
end
floorwidths(i)=input(['Enter floor:',num2str(mainlooptotal), ' width: ']);
if i>1
while(floorwidths(i)>floorwidths(i-1))
floorwidths(i)=input(['Floor length',num2str(floorwidths(i)),' is more than the floor bellow ',num2str(floorwidths(i-1)),' Please enter floor:',num2str(mainlooptotal), ' length']);
end
elseif floorwidths(i)<0
floorwidths(i)=input('Widths have to be >0. Please enter width!');
end
floorheights(i)=input(['Enter floor:',num2str(mainlooptotal), ' height: ']);
if i>1
while(floorheights(i)<floorheights(i-1))
floorheights(i)=input(['Floor height of ',num2str(floorheights(i)),' is lower then height ',num2str(floorheights(i-1)),' Please enter height:',num2str(mainlooptotal),' height']);
end
elseif floorheights(i)<0
floorheights(i)=input(('Floor height needs to be <0. Please enter floor height!'));
end
%include if they are <0
%Floor plotting
patch([0,floorlengths(i),floorlengths(i),0],[0,0,floorwidths(i),floorwidths(i)],[floorheights(i),floorheights(i),floorheights(i),floorheights(i)],'blue');
mainlooptotal=mainlooptotal+1; %put this after the spaces
numbspaces=input('Please input the number of spaces you wish to have on this floor: ');
for j=1:1:numbspaces
startpointx(j)=input(sprintf('Enter x coordinate start point for space %i :',j));
startpointy(j)=input(sprintf('Enter y coordinate start point for space %i :',j));
spacewidths(i,j)=input(sprintf('Enter floor %i width %i :', i,j));
spacelengths(i,j)=input(sprintf('Enter floor %i length %i :', i,j));
spaceheights(i,j)=input(sprintf('Enter floor %i height %i :', i,j));
%ISSUE IS DUE TO LINE 76
answer=menu('Choose type of space','Residential','Office','Education','Toilet','Storage');
if answer==1
patch([startpointx(j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)],[startpointy(j),startpointy(j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j)],[floorheights(i),floorheights(i),floorheights(i),floorheights(i)],'red')
patch([startpointx(j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)],[startpointy(j),startpointy(j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j)],[spaceheights(i,j)-0.01,spaceheights(i,j)-0.01,spaceheights(i,j)-0.01,spaceheights(i,j)-0.01],'red')
patch([startpointx(j),startpointx(j),startpointx(j),startpointx(j)],[startpointy(j),startpointy(j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j)],[floorheights(i),spaceheights(i,j)-0.01,spaceheights(i,j)-0.01,floorheights(i)],'red')
patch([startpointx(j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)],[startpointy(j),startpointy(j),startpointy(j),startpointy(j)],[floorheights(i),floorheights(i),spaceheights(i,j)-0.01,spaceheights(i,j)-0.01],'red')
patch([startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j)],[startpointy(j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j),startpointy(j)],[floorheights(i),floorheights(i),spaceheights(i,j)-0.01,spaceheights(i,j)-0.01],'red')
patch([startpointx(j)+spacelengths(i,j),startpointx(j),startpointx(j),startpointx(j)+spacelengths(i,j)],[startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j)],[floorheights(i),floorheights(i),spaceheights(i,j)-0.01,spaceheights(i,j)-0.01],'red')
elseif answer==2
patch([startpointx(j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)],[startpointy(j),startpointy(j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j)],[floorheights(i),floorheights(i),floorheights(i),floorheights(i)],'red')
patch([startpointx(j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)],[startpointy(j),startpointy(j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j)],[spaceheights(i,j)-0.01,spaceheights(i,j)-0.01,spaceheights(i,j)-0.01,spaceheights(i,j)-0.01],'red')
patch([startpointx(j),startpointx(j),startpointx(j),startpointx(j)],[startpointy(j),startpointy(j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j)],[floorheights(i),spaceheights(i,j)-0.01,spaceheights(i,j)-0.01,floorheights(i)],'red')
patch([startpointx(j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)],[startpointy(j),startpointy(j),startpointy(j),startpointy(j)],[floorheights(i),floorheights(i),spaceheights(i,j)-0.01,spaceheights(i,j)-0.01],'red')
patch([startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j)],[startpointy(j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j),startpointy(j)],[floorheights(i),floorheights(i),spaceheights(i,j)-0.01,spaceheights(i,j)-0.01],'red')
patch([startpointx(j)+spacelengths(i,j),startpointx(j),startpointx(j),startpointx(j)+spacelengths(i,j)],[startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j)],[floorheights(i),floorheights(i),spaceheights(i,j)-0.01,spaceheights(i,j)-0.01],'red')
elseif answer==3
patch([startpointx(j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)],[startpointy(j),startpointy(j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j)],[floorheights(i),floorheights(i),floorheights(i),floorheights(i)],'red')
patch([startpointx(j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)],[startpointy(j),startpointy(j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j)],[spaceheights(i,j)-0.01,spaceheights(i,j)-0.01,spaceheights(i,j)-0.01,spaceheights(i,j)-0.01],'red')
patch([startpointx(j),startpointx(j),startpointx(j),startpointx(j)],[startpointy(j),startpointy(j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j)],[floorheights(i),spaceheights(i,j)-0.01,spaceheights(i,j)-0.01,floorheights(i)],'red')
patch([startpointx(j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)],[startpointy(j),startpointy(j),startpointy(j),startpointy(j)],[floorheights(i),floorheights(i),spaceheights(i,j)-0.01,spaceheights(i,j)-0.01],'red')
patch([startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j)],[startpointy(j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j),startpointy(j)],[floorheights(i),floorheights(i),spaceheights(i,j)-0.01,spaceheights(i,j)-0.01],'red')
patch([startpointx(j)+spacelengths(i,j),startpointx(j),startpointx(j),startpointx(j)+spacelengths(i,j)],[startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j)],[floorheights(i),floorheights(i),spaceheights(i,j)-0.01,spaceheights(i,j)-0.01],'red')
elseif answer==4
patch([startpointx(j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)],[startpointy(j),startpointy(j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j)],[floorheights(i),floorheights(i),floorheights(i),floorheights(i)],'red')
patch([startpointx(j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)],[startpointy(j),startpointy(j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j)],[spaceheights(i,j)-0.01,spaceheights(i,j)-0.01,spaceheights(i,j)-0.01,spaceheights(i,j)-0.01],'red')
patch([startpointx(j),startpointx(j),startpointx(j),startpointx(j)],[startpointy(j),startpointy(j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j)],[floorheights(i),spaceheights(i,j)-0.01,spaceheights(i,j)-0.01,floorheights(i)],'red')
patch([startpointx(j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)],[startpointy(j),startpointy(j),startpointy(j),startpointy(j)],[floorheights(i),floorheights(i),spaceheights(i,j)-0.01,spaceheights(i,j)-0.01],'red')
patch([startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j)],[startpointy(j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j),startpointy(j)],[floorheights(i),floorheights(i),spaceheights(i,j)-0.01,spaceheights(i,j)-0.01],'red')
patch([startpointx(j)+spacelengths(i,j),startpointx(j),startpointx(j),startpointx(j)+spacelengths(i,j)],[startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j)],[floorheights(i),floorheights(i),spaceheights(i,j)-0.01,spaceheights(i,j)-0.01],'red')
elseif answer==5
patch([startpointx(j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)],[startpointy(j),startpointy(j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j)],[floorheights(i),floorheights(i),floorheights(i),floorheights(i)],'red')
patch([startpointx(j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)],[startpointy(j),startpointy(j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j)],[spaceheights(i,j)-0.01,spaceheights(i,j)-0.01,spaceheights(i,j)-0.01,spaceheights(i,j)-0.01],'red')
patch([startpointx(j),startpointx(j),startpointx(j),startpointx(j)],[startpointy(j),startpointy(j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j)],[floorheights(i),spaceheights(i,j)-0.01,spaceheights(i,j)-0.01,floorheights(i)],'red')
patch([startpointx(j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)],[startpointy(j),startpointy(j),startpointy(j),startpointy(j)],[floorheights(i),floorheights(i),spaceheights(i,j)-0.01,spaceheights(i,j)-0.01],'red')
patch([startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j),startpointx(j)+spacelengths(i,j)],[startpointy(j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j),startpointy(j)],[floorheights(i),floorheights(i),spaceheights(i,j)-0.01,spaceheights(i,j)-0.01],'red')
patch([startpointx(j)+spacelengths(i,j),startpointx(j),startpointx(j),startpointx(j)+spacelengths(i,j)],[startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j),startpointy(j)+spacewidths(i,j)],[floorheights(i),floorheights(i),spaceheights(i,j)-0.01,spaceheights(i,j)-0.01],'red')
end
%problem where spaces are not plotted above the second floor
%height
end
end
end
  3 Comments
Image Analyst
Image Analyst on 1 May 2022
Are you sure the code in each block is different? It looks the same, though I didn't scrutinize it. If they're all the same then no matter what answer is you'll get the same patches.

Sign in to comment.

Answers (1)

Nipun
Nipun on 29 Dec 2023
Hi Ethan,
I understand that you are trying to create a 3D spatial model in MATLAB based on user input, where the user can specify various parameters such as the number of floors, the dimensions of each floor, and the dimensions and locations of certain spaces within those floors. However, you are encountering an issue where, after plotting the second floor, the spaces intended to be 3D are only appearing as 2D.
On analyzing the provided code, it seems like all of the "patch" subroutines are identical for "if-else" statements.
The id-else code snippet can be summarized as follows:
if answer == 1
% series of patch commands with 'red' color
elseif answer == 2
% identical series of patch commands with 'red' color
elseif answer == 3
% identical series of patch commands with 'red' color
% ... and so on for answer == 4 and answer == 5
end
Therefore, MATLAB will produce identical patches irrespective of the value of answer variable.
Consider changing the arguments to the "patch" utility to get different outputs.
Hope this helps.
Regards,
Nipun

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!