Addition inside of an existing Matrix

I am trying to understand how to manipulate a matrix, can anyone please show me how to perform the following action in Matlab?
for example if I had a 2x2 matrix
[a,b;c,d]
How would I be able to achieve
[a,b;c,x+d]
e.g a=1, b=2, c=3, d=4,
if X=10
[1,2;3,X+5]

 採用された回答

matico
matico 2015 年 8 月 23 日

1 投票

M = [1, 2; 3, 4];
X = 10;
%%VERSION 1
M(end) = M(end) + X;
%%VERSION 2
M(2,2) = M(2,2) + X;
In both versions the M matrix become [1, 2; 3, 14]

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeOperating on Diagonal Matrices についてさらに検索

製品

質問済み:

2015 年 8 月 23 日

回答済み:

2015 年 8 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by