필터 지우기
필터 지우기

Adding Penalty for Violation

조회 수: 1 (최근 30일)
RDG
RDG 2011년 10월 23일
I have this code snippet that generates a matrix with the notation of chr(:,:,i)
for i=1:10
A=zeros(100,4);
A(:,1)=randi(100,100,1); %Course(1)
A(:,2)=randi(5,100,1); %Day(2)
A(:,3)=randi(10,100,1); %Timeslot(3)
A(:,4)=randi(17,100,1); %Room(4)
chr(:,:,i)=A
end
Is there a way to check for duplicate values (Assuming Row 1, Row 4 & Row 5 contain similar data) and for each time a repeated data is found, a violation score (Let's say 10) is imposed to chr(:,:,i)
For the eg, if Row 4 & Row 5 are similar to Row 1, a violation score of 2*10 should be imposed to chr(:,:,i)

채택된 답변

Image Analyst
Image Analyst 2011년 10월 23일
Well there are a variety of ways to do it, from brute force "for" loop ways to more efficient ways. After your for loop has finished creating the A array, I'd probably call sortrows() and then call diff(). Any row that has a repeat in it will have all zeros in a row of the array that diff() returns. Then check for all zero rows by using sum() or any(). Note which original row number this is by getting it from the index array that sortrows() returns (the second output arg). I expect that you're capable of handling the details, but that's how I'd start approaching it.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by