How do i create a matrix of size 1 row and 1501 column, with values [1 -1 1 -1 1 -1.... etc
Show older comments
(countinuously 1 then -1 repeating.
thanks Dan
Answers (3)
Bjorn Gustavsson
on 1 May 2012
v = (-1).^(0:n);
HTH
Wayne King
on 1 May 2012
One way:
x = ones(1,1501);
x(2:2:end) = -1*x(2:2:end);
Another way
y = repmat([1 -1],1,751);
y(end) = [];
1 Comment
Daniel Shub
on 1 May 2012
Hey, no fair on the edit ...
Daniel Shub
on 1 May 2012
[repmat([1,-1], 1, floor(1501/2)), 1]
Categories
Find more on Resizing and Reshaping Matrices 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!