Resizing a vector to a matrix

조회 수: 1 (최근 30일)
Ramanan Viswanathan
Ramanan Viswanathan 2015년 12월 9일
댓글: Stephen23 2015년 12월 9일
I have a vector which is of size 1x3. I want to resize to 13x3 matrix..is it possible to do it? how can i proceed

답변 (1개)

Stephen23
Stephen23 2015년 12월 9일
편집: Stephen23 2015년 12월 9일
It depends on how you want to resize the vector. If you simply want to replicate those values into every row of the final matrix, then try either of these methods:
>> X = [1,2,3]
X =
1 2 3
>> repmat(X,5,1)
ans =
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
>> X(ones(1,5),:)
ans =
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
Note that I created 5x3 matrices, but I am sure that you can figure out how to create 13x3 matrices.
  댓글 수: 3
James Tursa
James Tursa 2015년 12월 9일
@Ramanan: You need to be more specific. As Stephen has already stated, you need to tell us how you want this to be done. Maybe give us an example.
Stephen23
Stephen23 2015년 12월 9일
Here is another easy way to resize a vector, by adding a value and filling the rest with zeros:
>> X = [1,2,3]
X =
1 2 3
>> X(5,1) = 0
X =
1 2 3
0 0 0
0 0 0
0 0 0
0 0 0
I repeat my original comment: how do you want your matrix expanded (if not with replicated values)?

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

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by