フィルターのクリア

Confusion in Addition: adding 1:4 to a matrix of 1X4 gives resultant matrix of 1X5

2 ビュー (過去 30 日間)
If A = [1 0;0 1] then how would 1:4 + A(:)' = 1 2 3 4 5

採用された回答

Guillaume
Guillaume 2017 年 8 月 31 日
Because of operator precedence, + has more priority than :. Therefore your expression is equivalent to :
1 : (4 + A(:)')
which is
1 : ([5; 4; 4; 5])
Because of the colon rule, only the first element of a vector is considered, the above is thus equivalent to:
1 : 5
I suspect you may have wanted
(1:4) + A(:)'
which will result in a 1x4 vector pre-R2016b (or it may error, I can't remember) and in a 4x4 matrix in R2016b or later.
  1 件のコメント
Ihsan Ullah
Ihsan Ullah 2017 年 9 月 1 日
Thanks Guillaume for your prompt positive support! Appreciated.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by