How do you set the first column of a 4x4 matrix = a vector

조회 수: 21 (최근 30일)
Vincent Ogonda
Vincent Ogonda 2020년 8월 13일
댓글: hosein Javan 2020년 8월 13일
Vector X [380 250 220 200]
Matrix C=
[1257 679 220 203 1567 155 234 432 2345 445 238 556] How do I set the first column of matrix C equal to x
  댓글 수: 1
Rik
Rik 2020년 8월 13일
You will probably benefit from a tutorial to get started with Matlab. One of the free options is Onramp.

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

채택된 답변

hosein Javan
hosein Javan 2020년 8월 13일
편집: hosein Javan 2020년 8월 13일
X = [380 250 220 200]
C=[1257 679 220 203
1567 155 234 432
2345 445 238 556];
C(1,:)=X; % set the first row of C equal to vector X
size of C = 3*4 , and size of X = 1*4. you can set the first row of C equal to X. if not, I assume it was:
X = [380; 250; 220; 200]
C=[1257 679 220
203 1567 155
234 432 2345
445 238 556];
C(:,1)=X; % set the first column of C equal to vector X
  댓글 수: 5
Vincent Ogonda
Vincent Ogonda 2020년 8월 13일
X = [380; 250; 220; 200] C=[1257 679 220 203 1567 155 234 432 2345 445 238 556]; C(:,1)=X; % set the first column of C equal to vector X
It worked for the row and not the column. Error in simulation it shows
hosein Javan
hosein Javan 2020년 8월 13일
please copy and paste the code to your matlab command window. you have mistakenly defined matrix "C" as a row-vector rather than a 4*3 matrix. if you want to define a matrix in one line of code, use semicolon";" to distinguish rows.
C=[1257 679 220; 203 1567 155; 234 432 2345; 445 238 556];

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by