How can I create a vector like this : X = [1, 2, 1, 2 ......
Show older comments
Hi,
How can I create a vector X = [ 1, 2, 1, 2 ....... ] with n value.(which n value can be odd or even).
Is there possible to use only two instructions?
thanks.
2 Comments
Walter Roberson
on 2 Mar 2021
Is there possible to use only two instructions?
No. You need a minimum of 3 instructions even for the case where n is even. You can construct 1:2 or [1 2] but either way that takes one instruction. You need to divide n by 2, which takes one instruction. Replicating the vector takes a minimum of 1 instruction.
You can do the whole thing in four instructions if it is acceptable to have two assignment statements. I think it might take 6 instructions if you are only permitted to use a single assignment statement.
cheng en tsai
on 2 Mar 2021
Accepted Answer
More Answers (1)
Categories
Find more on App Building in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!