Borrar filtros
Borrar filtros

Quick Question! Get the Index

2 visualizaciones (últimos 30 días)
Xiao Tang
Xiao Tang el 11 de Ag. de 2012
Hi guys, I have a matrix A,
A = [1;1;0;1;1;1;0]
As you can see, A(3) =0;A(7) = 0;
Is there any function or logical index I can use to get[3;7]?
Thanks!

Respuesta aceptada

Matt Fig
Matt Fig el 11 de Ag. de 2012
Editada: Matt Fig el 11 de Ag. de 2012
idx = find(~A)
or
idx = find(A~=0)
or
idx = find(A==0)
or (this might be much faster if you are doing this in a FOR loop)
I = 1:length(A); % Define outside loop
idx = I(A==0) % If A is changing every iteration, but not numel.
% or I(~A), etc.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by