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.
Adding Penalty for Violation
2 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!