X=(x0,x1,....,Xn0-1) ==> Xhat=(x0,x0,x0,x0, x1,x1,x1,x1, ........ ,Xn0-1,Xn0-1,Xn0-1,Xn0-1), How can I copy like this in vector?
3 views (last 30 days)
Show older comments
DongShin Yang
on 29 Jun 2015
Commented: Walter Roberson
on 29 Jun 2015
X=(x0,x1,....,Xn0-1) ==> Xhat=(x0,x0,x0,x0, x1,x1,x1,x1, ........ ,Xn0-1,Xn0-1,Xn0-1,Xn0-1)
How can I copy like in vector?
x0 was copied number of 4(or any number)
0 Comments
Accepted Answer
Walter Roberson
on 29 Jun 2015
xhat = kron(X, ones(1,4))
2 Comments
Walter Roberson
on 29 Jun 2015
MATLAB does not have a syntax
X= 1 2 3 4
so that was not the way you created the vector.
The output you got tells me that your X is not a row vector like you asked in your question: your X is a column vector.
In the general case where you do not know whether you have a row vector or a column vector but you know for sure you want to end up with a row vector, then use
Xhat = kron(X(:).', ones(1,4))
or
Xhat = kron(reshape(X,1,[]), ones(1,4))
X(:).' and reshape(X,1,[]) do the same thing in different ways.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!