Matlab is summing a row with a column

2 ビュー (過去 30 日間)
Gonzalo Benavides
Gonzalo Benavides 2017 年 6 月 8 日
コメント済み: Image Analyst 2017 年 6 月 8 日
Hello everyone:
Today I started working with Matlab 2017a and I found what I think is a bug. When I sum [1,2]+[1;2], Matlab is returning [2,3;3,4]. Do you know how to make Matlab warn me when I sum vectors with different dimmensions?

採用された回答

Image Analyst
Image Analyst 2017 年 6 月 8 日
It's not a bug. It's the way the new MATLAB works now. It's called "automatic expansion."
Mathematics Implicit Expansion: Apply element-wise operations and functions to arrays with automatic expansion of dimensions of length 1
Implicit expansion is a generalization of scalar expansion. With scalar expansion, a scalar expands to be the same size as another array to facilitate element-wise operations. With implicit expansion, the element-wise operators and functions listed here can implicitly expand their inputs to be the same size, as long as the arrays have compatible sizes. Two arrays have compatible sizes if, for every dimension, the dimension sizes of the inputs are either the same or one of them is 1. See Compatible Array Sizes for Basic Operations and Array vs. Matrix Operations for more information.
  2 件のコメント
Gonzalo Benavides
Gonzalo Benavides 2017 年 6 月 8 日
Thank you so much for the info. Have a great day.
Image Analyst
Image Analyst 2017 年 6 月 8 日

You're welcome. Thanks for accepting.

By the way, the image below explains it pretty well:

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by