Filter löschen
Filter löschen

Adding Penalty for Violation

1 Ansicht (letzte 30 Tage)
RDG
RDG am 23 Okt. 2011
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)

Akzeptierte Antwort

Image Analyst
Image Analyst am 23 Okt. 2011
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.

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by