X=(x0,x1,....,Xn0-1) ==> Xhat=(x0,x0,x0,x0, x1,x1,x1,x1, ........ ,Xn0-1,Xn0​-1,Xn0-1,X​n0-1), How can I copy like this in vector?

3 views (last 30 days)
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)

Accepted Answer

Walter Roberson
Walter Roberson on 29 Jun 2015
xhat = kron(X, ones(1,4))
  2 Comments
DongShin Yang
DongShin Yang on 29 Jun 2015
Edited: Walter Roberson on 29 Jun 2015
Thank for your help.
Please, help me.
X= 1 2 3 4
Xhat = kron(X,ones(1,4))
Xhat = 1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
size(xhat) = 4x4
but
I want to chane Xhat like this
[1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4]
size(xhat) = 1x16
Walter Roberson
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.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!