I would like to add the integer 1 to every element in a matrix, except for the elements in the first column. I would like to use the function bsxfun since the matrix I wish to add 1 to is very large. What would be the correct syntax for this?

 採用された回答

Stephen23
Stephen23 2018 年 6 月 15 日
編集済み: Stephen23 2018 年 6 月 15 日

0 投票

M(:,2:end) = M(:,2:end)+1
or
V = ones(1,size(M,2));
V(1) = 0;
M = bsxfun(@plus,M,V)

1 件のコメント

Michiel Op De  Beeck
Michiel Op De Beeck 2018 年 6 月 15 日
Thank you very much! Works perfectly for the problem posed.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Mathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by