Filter löschen
Filter löschen

I got a task From my group studying class the Question is Quite confusing and I'm New to matlab. Here Is my Question and Plz Help me guys.

1 Ansicht (letzte 30 Tage)
Write a Matlab script that, given the capacity of each room in the building and the size of a class, will attempt to find satisfactory room assignment that will accommodate the class in the building. If the class cannot be satisfactory placed, the script should print a “Room is not available” message, otherwise, a message saying that “Room number XX which has YY seats, is best for the class of size ZZ”.
An array indexed from 1 to 10 should be convenient structure for representing the capacities of each room in the building. The indices of the array element represent the room number as pictured below
To find a satisfactory room assignment (Best fit room number for a given class size), the number of leftover –remaining- seats for the room when the assignment is made should be minimum, where the (leftover seats) = (room capacity) - (class size).
  4 Kommentare

Melden Sie sich an, um zu kommentieren.

Antworten (3)

Image Analyst
Image Analyst am 2 Dez. 2016
Here's a start. I trust you can finish it:
numClasses = 10;
roomCapacities = sort(randi(200, 1, numClasses), 'descend') % Sample data.
classSizes = sort(randi(200, 1, numClasses), 'descend')
classroomOccupied = false(1, numClasses)
for k = 1 : numClasses
for c = 1 : numClasses
if classSizes(k) < roomCapacities(c) && ~classroomOccupied(c)
% Code for you to finish....
end
end
end
This is only one way of many, I'm sure.
  4 Kommentare
Image Analyst
Image Analyst am 3 Dez. 2016
Where in the last 3 lines of the code I posted for you do you see a loop? Here they are again:
emptySeats = roomCapacities - classSize;
emptySeats(emptySeats < 0) = inf;
[minValue, index] = min(emptySeats);
There is no loop there. Which line has a "for" or "while" word on it?

Melden Sie sich an, um zu kommentieren.


Andrei Bobrov
Andrei Bobrov am 3 Dez. 2016
r = [12 23 44 54 23 6 65 100 212 45]
c = [70,6,23,200]'
[a,b] = sort(r(:))
[ii,~] = find(cumsum((a(:) - c(:)') >= 0) == 1)
out = [b(ii),a(ii),c(:)]

Abu Yamen
Abu Yamen am 4 Dez. 2016
we should not use loop in this q only we can use find function and size then fprintf
  1 Kommentar
Walter Roberson
Walter Roberson am 4 Dez. 2016
It says that you cannot use loops but where does it say that you must use find()? There is a perfectly good solution with sort and interp1

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by