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

1 visualización (últimos 30 días)
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 )

Respuesta aceptada

Walter Roberson
Walter Roberson el 26 de Oct. de 2020
Editada: Walter Roberson el 26 de Oct. de 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.

Más respuestas (0)

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by