What determines the shape of a logically indexed array?

7 Ansichten (letzte 30 Tage)
Ondrej Budac
Ondrej Budac am 3 Apr. 2014
Beantwortet: Ondrej Budac am 7 Apr. 2014
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.

Akzeptierte Antwort

Ondrej Budac
Ondrej Budac am 7 Apr. 2014
Just to complete the story, the answer seems to be:
If B is a logical array and A is any array, then A(B) is equivalent (but faster) way to produce the same result as A(find(B)), including the shape of the output.

Weitere Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 3 Apr. 2014
Maybe you need
a = ones(3,3);
b = a([true, true],:)
  7 Kommentare
Azzi Abdelmalek
Azzi Abdelmalek am 3 Apr. 2014
Just one question, what are you expecting with a(logical([1 0;1 1])) ? The result contains 3 elements
Ondrej Budac
Ondrej Budac am 3 Apr. 2014
If I now understand logical indexing correctly, I expect a(logical([1 0;1 1])) to give a column vector with values 1, 4, 2, assuming your definition of a.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by