Extract and count specific values from array

10 views (last 30 days)
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
Gregory Hind
Gregory Hind on 29 Apr 2020
Hi, we haven't been taught in great detail about a lot of stuff, just the basics like input, disp, making and changing specific values in arrays. There's a lot of self study required and it's getting a bit complicated, each space must have its own dimensions, location and type, which I have done. Next is extracting that data to calculate the total floor space of each type, the total volume of each space and each floor, and teh total volume of the building.
I just found how to count the number of each type of space and the volume of each space so that's ok.
Gregory Hind
Gregory Hind on 29 Apr 2020
I'll check out categorical etc, thanks

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!