Logical Manipulation of Vector

1 次查看(过去 30 天)
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 个评论
Oleg Komarov
Oleg Komarov 2011-9-5
He intended b rows of logical zeros.
Paulo Silva
Paulo Silva 2011-9-5
thanks Oleg :) now I understand.

请先登录,再进行评论。

采纳的回答

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

更多回答(2 个)

Daniel Shub
Daniel Shub 2011-9-5
[true(a, 1); false(b, 1)]

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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by