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

1 vue (au cours des 30 derniers jours)
K Hs
K Hs le 26 Oct 2020
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 )

Réponse acceptée

Walter Roberson
Walter Roberson le 26 Oct 2020
Modifié(e) : Walter Roberson le 26 Oct 2020
[~, 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.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Object Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by