フィルターのクリア

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 回表示 (過去 30 日間)
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 件のコメント
Abdulrehman Khan
Abdulrehman Khan 2016 年 12 月 2 日
Sir here is the sample run and thanks in advance
Abdulrehman Khan
Abdulrehman Khan 2016 年 12 月 2 日
編集済み: Abdulrehman Khan 2016 年 12 月 2 日
here is some more info for the function

サインインしてコメントする。

回答 (3 件)

Image Analyst
Image Analyst 2016 年 12 月 2 日
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 件のコメント
Abdulrehman Khan
Abdulrehman Khan 2016 年 12 月 3 日
Thank You sir but we advise not to use loop
Image Analyst
Image Analyst 2016 年 12 月 3 日
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?

サインインしてコメントする。


Andrei Bobrov
Andrei Bobrov 2016 年 12 月 3 日
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 2016 年 12 月 4 日
we should not use loop in this q only we can use find function and size then fprintf
  1 件のコメント
Walter Roberson
Walter Roberson 2016 年 12 月 4 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by