Azzera filtri
Azzera filtri

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 visualizzazione (ultimi 30 giorni)
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 Commenti

Accedi per commentare.

Risposte (3)

Image Analyst
Image Analyst il 2 Dic 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 Commenti
Image Analyst
Image Analyst il 3 Dic 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?

Accedi per commentare.


Andrei Bobrov
Andrei Bobrov il 3 Dic 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 il 4 Dic 2016
we should not use loop in this q only we can use find function and size then fprintf

Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by