Is there any ways to find all elements' rows and cols number at once?

조회 수: 1 (최근 30일)
K Hs
K Hs 2020년 10월 26일
편집: Walter Roberson 2020년 10월 26일
I'm keep finding if there's any way to find all elements' rows and cols number at once..
I need to put elements' column number to table.. (Dont need row number..)
There are many data, so i can't do it manually.
for example
A=[1,2,3;4,5,6]
I want to find each elements' column number
results like,
ans=1 2 3 1 2 3
(cause each elements' column number is 1 2 3 1 2 3 )

채택된 답변

Walter Roberson
Walter Roberson 2020년 10월 26일
편집: Walter Roberson 2020년 10월 26일
[~, column_numbers] = find(Array)
[~, column_numbers] = find(Array == value) %or any relationship
Note: in the specific case where there is exactly one matching column per row, or you only want the first or last match per row, there are some alternatives that do not involve find(). They can involve processing the array multiple times, but in a way that can be automatically vectorized.
Caution: if you are working on the case where there is exactly one match per row, then chances are that you would consider the result of the above find() to be out of order, as it will not be ordered by increasing row. To order by increasing row use
[column_numbers, ~] = find(Array .');
This has to do with the order that MATLAB stores arrays.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by