Logical Manipulation of Vector
Show older comments
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 Comments
Paulo Silva
on 5 Sep 2011
not easy to understand, please provide one simple example, rows=0 is something like this: []
Oleg Komarov
on 5 Sep 2011
He intended b rows of logical zeros.
Paulo Silva
on 5 Sep 2011
thanks Oleg :) now I understand.
Accepted Answer
More Answers (2)
Daniel Shub
on 5 Sep 2011
[true(a, 1); false(b, 1)]
Walter Roberson
on 5 Sep 2011
Something like,
kron([true;false],[a;b])
Unfortunately I cannot reach my server today to test this.
2 Comments
Oleg Komarov
on 5 Sep 2011
It could have been the most elegant, although with some overhead but the result is:
ans =
10
15
0
0
Walter Roberson
on 6 Sep 2011
I usually get kron() wrong the first few times... :(
Categories
Find more on Programming in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!