what it does mean?

조회 수: 2 (최근 30일)
Nyam Jargalsaikhan
Nyam Jargalsaikhan 2021년 1월 12일
댓글: David Hill 2021년 1월 12일
If index(1,1)==1
S1=0;
S2=1;
end

답변 (2개)

Cris LaPierre
Cris LaPierre 2021년 1월 12일
See MATLAB Onramp, in particular Chs 2, 5, 8, 12 & 13.

David Hill
David Hill 2021년 1월 12일
If the matrix 'index' indexed at (1,1) equals 1, then assign S1 =0 and S2 = 0.
if index(1,1)==1
S1=0;
S2=1;
end
  댓글 수: 2
Nyam Jargalsaikhan
Nyam Jargalsaikhan 2021년 1월 12일
편집: Nyam Jargalsaikhan 2021년 1월 12일
A=[1 5 7 8 4 2 6 3];
[~, index]=sort(A);
if index(1,1)==1
S1=0;
S2=0;
end
if index(1,1)==2
S1=0;
S2=0;
end
if index(1,1)==3
S1=0;
S2=0;
end
what about this one?
David Hill
David Hill 2021년 1월 12일
Matlab has good documentation. You should look at the sort() function.
help sort
You will see that the index array contains the index numbers for rearraigning A to sort it.
A(index)==sort(A);
The code above seems poorly written. First, index is only one dimension, so you only need to index at (1). Second, all if statements do the same thing so combining them into a single statement would be better.
A=[1 5 7 8 4 2 6 3];
[~, index]=sort(A);
if ismember(index(1),[1 2 3])
S1=0;
S2=0;
end

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by