Change rows in a matrix so that no number is repeated more than 3 times in each column
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi there,
Currently I am using the script below to change the order of rows in a matrix such that no number is repeated consecutively in either the first or second column. How do I change the script such that numbers can be repeated twice or three times, but no more?
Many thanks,
James
function d=repcheck(b,s)
%The input b is a matrix
%The input s is the number of rows
e=0; for c=1:s d(c,:)=b(1+e,:); b(1+e,:)=[];e=0;
while((isempty(b)) || (d(c,1)==b(1+e,1))||(d(c,2)==b(1+e,2)));
e=e+1;
if ((e>=(numel(b(:,1))-1)) || (numel(b(:,1))<2))
d=[d;b];
return
end
end
end
0 commentaires
Réponses (2)
Matt Kindig
le 18 Avr 2012
I'm not sure what you are trying to do. I tested this script with the input matrix:
8 8 91
9 9 18
91 77 26
15 15 15
83 87 14
54 8 87
100 100 58
8 26 55
44 80 14
11 43 85
and it just returned out my original matrix. Can you post an example matrix of what you are trying to do?
0 commentaires
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!