how we find a particular number from the matrix in matlab????
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
A=[2 3 4;5 4 6;7 8 4] suppose we want to select '4' of 1st row of 3rd column,2nd row of 2nd column and 3rd row of 3rd column.how did we find this number?????
채택된 답변
It is not clear what numbers you want: when you write that you want "this number", are you referring to the indices of the fours in that matrix, or the fours themselves, or perhaps some other numbers? If you don't tell us exactly what you want, or what you need to do with these numbers, then it is difficult for us to provide you with a clear answer.
It seems that you want the indices of the fours, in which case here are some possible ways to get indices of values in a matrix:
>> A=[2 3 4;5 4 6;7 8 4] % data matrix
A =
2 3 4
5 4 6
7 8 4
>> [R,C] = find(A==4) % row and column indices
R =
2
1
3
C =
2
3
3
>> L = find(A==4) % linear indices
L =
5
7
9
>> X = A==4 % logical indices
X =
0 0 1
0 1 0
0 0 1
And of course you can use any of these to extract those value from the matrix:
>> A(X)
ans =
4
4
4
You can read more about indexing in the documentation:
댓글 수: 8
thank u so much for solve my problem
A=[11 5 6 3 10 8 7 4 2 9 1;6 3 11 7 8 5 1 2 4 9 10;10 8 11 6 7 3 9 5 4 1 2;7 1 2 5 9 8 4 10 11 3 6;11 10 1 7 3 2 4 9 8 5 6].suppose we want to find whether 3, & 6 then which operator we have to choose???
You don't really tell us how you want to use this, which actually decides what method you want to use. So without any further details of what you are trying to achieve, you could use logical indexing:
>> A=[11 5 6 3 10 8 7 4 2 9 1;6 3 11 7 8 5 1 2 4 9 10;10 8 11 6 7 3 9 5 4 1 2;7 1 2 5 9 8 4 10 11 3 6;11 10 1 7 3 2 4 9 8 5 6]
A =
11 5 6 3 10 8 7 4 2 9 1
6 3 11 7 8 5 1 2 4 9 10
10 8 11 6 7 3 9 5 4 1 2
7 1 2 5 9 8 4 10 11 3 6
11 10 1 7 3 2 4 9 8 5 6
>> X = A==3 | A==6
X =
0 0 1 1 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0 0
0 0 0 1 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1 1
0 0 0 0 1 0 0 0 0 0 1
>> A(X)
ans =
6
3
6
3
6
3
3
3
6
6
Also note that on MATLAB Answers it is considered polite to Accept an answer that best resolves your question.
how we partitioning this matrix.suppose 3 & 6 training data set or other than testing data set??
Then you can use the logical indexing to select the training and test sets:
trainSet = A(X);
testSet = A(~X);
thx a lot
how we find trainSet or testSet in form of row or column????
It is not clear what you mean by "how we find trainSet or testSet in form of row or column": do you want to select columns of data from the matrix, or split the matrix column-wise into test and training sets?
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
태그
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
