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 Center および File ExchangeGraphics Object Programming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by