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
rowVec(2:5)=y
Is there a way to do this in one line of code?
Thanks C

 채택된 답변

James Tursa
James Tursa 2018년 3월 23일
편집: James Tursa 2018년 3월 23일

2 개 추천

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?

댓글 수: 1

Chet Sharma
Chet Sharma 2018년 3월 23일
Thanks!! I tried everything except look at repmat..my bad! To answer your question, nothing wrong with what I wrote, but exactly as you said right...the number of y's I have changes, so I need to generalize. So your solution is exactly what I needed. Thanks James

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2018년 3월 23일

댓글:

2018년 3월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by