What determines the shape of a logically indexed array?
Mostrar comentarios más antiguos
Matlab help explains: " Logical Indexing : ... The output is always in the form of a column vector."
In practice, typing
a = ones(3,3);
b = a([true, true]);
gives a row vector b. Can someone tell me why does it behave this way? And is there any other instance (apart from indexing by one row logical vector) that gives a non-column result? Thanks, O.
Respuesta aceptada
Más respuestas (1)
Azzi Abdelmalek
el 3 de Abr. de 2014
Maybe you need
a = ones(3,3);
b = a([true, true],:)
7 comentarios
Ondrej Budac
el 3 de Abr. de 2014
Editada: Ondrej Budac
el 3 de Abr. de 2014
Azzi Abdelmalek
el 3 de Abr. de 2014
a = ones(3,3);
a is a 3x3 array
your index is idx=[true, true] is a 1x2 array, the result a(idx) is obviously a 1x2 array.
Ondrej Budac
el 3 de Abr. de 2014
Editada: Ondrej Budac
el 3 de Abr. de 2014
Azzi Abdelmalek
el 3 de Abr. de 2014
Editada: Azzi Abdelmalek
el 3 de Abr. de 2014
Ok,
a=[1 2 3 ;4 5 6;7 8 9]
a([4 5;3 1]) % is a 2x2 array
% but if you use logical indexing
a(logical([1 0;1 1]))
% this is equivalent to a([1 2 4])
Ondrej Budac
el 3 de Abr. de 2014
Editada: Ondrej Budac
el 3 de Abr. de 2014
Azzi Abdelmalek
el 3 de Abr. de 2014
Just one question, what are you expecting with a(logical([1 0;1 1])) ? The result contains 3 elements
Ondrej Budac
el 3 de Abr. de 2014
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!