필터 지우기
필터 지우기

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

댓글을 달려면 로그인하십시오.

답변 (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
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 CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by