problem in inserting a diagnol

hi, i have a problem in inserting the diagnol of a matrix. i have a=[1 2 3;4 5 6;7 8 9] in which i have to extract the diagnol by multiplying with 2 and i want to again insert the diagnol i,e iwant to have [2 2 3;4 10 6;7 8 18]; i dont want to use the loop.

3 件のコメント

the cyclist
the cyclist 2012 年 7 月 12 日
編集済み: the cyclist 2012 年 7 月 12 日
Seems like a homework problem. What have you tried already? (Also, should that 27 actually be an 18?)
Yash
Yash 2012 年 7 月 12 日
how do u want the output to be
San
San 2012 年 7 月 12 日
he want to have double for diagonal but don't want loop :(

サインインしてコメントする。

回答 (1 件)

Conrad
Conrad 2012 年 7 月 12 日

0 投票

A = [ 1 2 3;...
4 5 6;...
7 8 9];
A(1:(length(A)+1):numel(A)) = 2*diag(A);

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2012 年 7 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by