Logical Manipulation of Vector

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

not easy to understand, please provide one simple example, rows=0 is something like this: []
He intended b rows of logical zeros.
thanks Oleg :) now I understand.

Sign in to comment.

 Accepted Answer

a = 10;
b = 20;
lg = [true (a,1)
false(b,1)];

More Answers (2)

Something like,
kron([true;false],[a;b])
Unfortunately I cannot reach my server today to test this.

2 Comments

It could have been the most elegant, although with some overhead but the result is:
ans =
10
15
0
0
I usually get kron() wrong the first few times... :(

Sign in to comment.

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!