필터 지우기
필터 지우기

How to stick on/augmenting a vector into the matrix?

조회 수: 16 (최근 30일)
Isti
Isti 2012년 4월 26일
댓글: Walter Roberson 2017년 4월 17일
If i have a matrix like this:
2 1 4 6 2
9 4 6 1 2
5 3 2 8 3
7 2 1 9 3
7 1 8 2 4
3 5 4 1 2
then i want to stick on a vektor contain of "1" in the beginning of that matrix. so it'll be like this:
1 2 1 4 6 2
1 9 4 6 1 2
1 5 3 2 8 3
1 7 2 1 9 3
1 7 1 8 2 4
1 3 5 4 1 2
what to do? thanks before :')
  댓글 수: 2
Ashley Velasco
Ashley Velasco 2017년 4월 17일
편집: Ashley Velasco 2017년 4월 17일
I'm a student just learning how to use MATLAB... but I'm pretty sure you can use the horzcat function to do it easily. Matlab has documentation on it.
https://www.mathworks.com/help/matlab/ref/horzcat.html
Walter Roberson
Walter Roberson 2017년 4월 17일
The [] operator defaults to horzcat, so the solution I listed
[ones(size(TheMatrix,1),1), TheMatrix]
is really the same as
horzcat( ones(size(TheMatrix,1),1), TheMatrix)

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

채택된 답변

Walter Roberson
Walter Roberson 2012년 4월 26일
NewMatrix = [ones(size(TheMatrix,1),1), TheMatrix];
  댓글 수: 2
Isti
Isti 2012년 4월 26일
i'm sorry but it's not suitable in my case. is there any?
thanks
Walter Roberson
Walter Roberson 2012년 4월 26일
Sorry, I've corrected.

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

추가 답변 (2개)

Isti
Isti 2012년 4월 26일
then the result is like this:
1 1 1 1 1 1 2 1 4 6 2
1 1 1 1 1 1 9 4 6 1 2
1 1 1 1 1 1 5 3 2 8 3
1 1 1 1 1 1 7 2 1 9 3
1 1 1 1 1 1 7 1 8 2 4
1 1 1 1 1 1 3 5 4 1 2
is there another solution?

ike
ike 2012년 4월 26일
yours= [ 2 1 4 6 2; 9 4 6 1 2; 5 3 2 8 3; 7 2 1 9 3; 7 1 8 2 4; 3 5 4 1 2]
add=ones(6,1); concat=[add yours]
try this....

카테고리

Help CenterFile Exchange에서 Newton-Raphson Method에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by