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

18 ビュー (過去 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by