Extract and count specific values from array
15 views (last 30 days)
Show older comments
My course work has asked me to allow the user to define the amount of rooms/spaces, ask for dimensions, type of space and then draw the floor plan for each floor and calculate volumes and cost etc. I'm about half way through but I'm struggling how to count the amounts of each type of room and use that data to create volumes etc. So, how many spaces were 'Educational', and what is the total floor space of that type?
Also, each rectangle must be deleted before the next iteration of the loop for each floor or the new rectangle isn't created.
Any ideas?
clc;
clear;
floors=[];
spaces=[];
X=[];
Y=[];
T=[];
err='Not a high enough value';
floors=input('Please enter the number of floors: ');
while floors<=0;
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),': ']);
while spaces<=0
disp(err)
spaces(a)=input(['Enter number of spaces on floor ',num2str(a),': ']);
end
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),': ']);
type=menu(['Select type of space number ',num2str(b),' on floor',num2str(a),': '],'Education','Office','Residential','Storage','Toilet');
T(a,b)=type;
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
for b=1:1:spaces
rectangle('Position',[X(a,b),Y(a,b),width(a,b),depth(a,b)]);
end
end
3 Comments
Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!