Azzera filtri
Azzera filtri

Logical Manipulation of Vector

1 visualizzazione (ultimi 30 giorni)
John
John il 5 Set 2011
I require a logical vector with 'a' number of rows =1 and followed by 'b' rows =0. How can I create this without if statements?
I know a and b.
  3 Commenti
Oleg Komarov
Oleg Komarov il 5 Set 2011
He intended b rows of logical zeros.
Paulo Silva
Paulo Silva il 5 Set 2011
thanks Oleg :) now I understand.

Accedi per commentare.

Risposta accettata

Oleg Komarov
Oleg Komarov il 5 Set 2011
a = 10;
b = 20;
lg = [true (a,1)
false(b,1)];

Più risposte (2)

Daniel Shub
Daniel Shub il 5 Set 2011
[true(a, 1); false(b, 1)]

Walter Roberson
Walter Roberson il 5 Set 2011
Something like,
kron([true;false],[a;b])
Unfortunately I cannot reach my server today to test this.
  2 Commenti
Oleg Komarov
Oleg Komarov il 5 Set 2011
It could have been the most elegant, although with some overhead but the result is:
ans =
10
15
0
0
Walter Roberson
Walter Roberson il 6 Set 2011
I usually get kron() wrong the first few times... :(

Accedi per commentare.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by