Create a row vector with specific condition
2 views (last 30 days)
Show older comments
Commented: Chet Sharma on 23 Mar 2018
Hi I'd like to make a row vector as follows:
rowVect = [x y y y y y]
Right now, I'm doing:
rowVec = x
Is there a way to do this in one line of code?
James Tursa on 23 Mar 2018
Edited: James Tursa on 23 Mar 2018
What's wrong with the first method you propose?
rowVect = [x y y y y y];
If you want to generalize it (maybe you don't know the number of y's you need ahead of time)
n = number of y's you want
rowVect = [x,repmat(y,1,n)];
That being said, your two-liner above is a pretty good way of doing it. Is there some particular reason you don't like it?
More Answers (0)
Find more on Creating and Concatenating 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!