Extract and count specific values from array
Ältere Kommentare anzeigen
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 Kommentare
dpb
am 29 Apr. 2020
They taught you about categorical variables and tables, yet?
Look up grouping variables in the documentation.
It would seem to be a lot to ask the user to figure out the locations while sitting at the keyboard -- would seem the app should place them for them...
Is it required to specify every room size individually or a size for a type of room and the number of those? Then you have the problem constrained to a tiling of fixed number of same-sized elements of however many types there are.
Otherwise, unless there are something constraints in the problem, it would seem pretty difficult to handle generically for a beginning class...
Gregory Hind
am 29 Apr. 2020
Gregory Hind
am 29 Apr. 2020
Antworten (0)
Kategorien
Mehr zu Matrix Indexing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!