Change rows in a matrix so that no number is repeated more than 3 times in each column
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
Matt Kindig
2012 年 4 月 18 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!