if i have random matrices how to find a specific matrix?
1 回表示 (過去 30 日間)
古いコメントを表示
if i have a random 20 binary matrix and matrix A ;
A = [ 1 0 1 1
0 1 0 0
1 1 0 1
1 1 0 1 ]
s =[ 1 0 1 0
1 1 0 0
0 1 1 0
0 0 1 0 ]
s = [ 1 1 0 1
0 1 0 0
1 1 0 1
0 1 0 1 ]
.
.
.
.
s = [ 1 0 1 0
0 0 0 1
1 1 1 0
1 0 1 1 ]
and after apply some operation i want to find the minimum value and then return the matrix that have the minimum value
this is my code
for k=1:20
s = randi ([0 1 ] ,4,4);
S(k)=(sum (sum(A ~= s)));
end
s7=min(S)
how can return the tow matrix have the min value??
1 件のコメント
John D'Errico
2016 年 4 月 17 日
You seem to be asking pretty basic questions in programming (over and over again) in a very confused way. That suggests the best solution is for you to spend some time learning programming. Pick up a basic text on MATLAB, and start reading. Do the examples. Try the problems suggested.
回答 (2 件)
John D'Errico
2016 年 4 月 17 日
Why not just save the current matrix, IF your computation is better than the previous best solution? This requires only an if statement inside the loop, and that you store the current best objective function at any point in time.
0 件のコメント
Azzi Abdelmalek
2016 年 4 月 17 日
A = [ 1 0 1 1
0 1 0 0
1 1 0 1
1 1 0 1 ]
for k=1:20
s = randi ([0 1 ] ,4,4);
M{k}=s;
S(k)=(sum (sum(A ~= s)));
end
[s7,idx]=min(S)
out=M{idx}
6 件のコメント
Walter Roberson
2016 年 4 月 19 日
Firas got impatient for immediate response and opened a new Question on the same topic, http://www.mathworks.com/matlabcentral/answers/279771-how-to-find-min-value-among-20-random-matrices-and-return-the-min-matrix-have-the-min-value
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!