필터 지우기
필터 지우기

if i have random matrices how to find a specific matrix?

조회 수: 2 (최근 30일)
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016년 4월 17일
댓글: Walter Roberson 2016년 4월 19일
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
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
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.

Azzi Abdelmalek
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
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016년 4월 19일
when i copy the code this statement appear
(Insufficient number of outputs from right hand side of equal sign to satisfy assignment.)
[s7,idx]=min(S);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by