Does different MATLAB versions handle array arithmetic differently ?

1 回表示 (過去 30 日間)
Ronny Landsverk
Ronny Landsverk 2018 年 6 月 8 日
コメント済み: James Tursa 2018 年 6 月 8 日
In a previous project I did something like
x = randn(N,3); % N > 1
x = x - [x,y,z]; % remove "bias", x,y,z are scalars
Im am pretty sure that this was allowed in a previous version of MATLAB. Am I wrong ?

回答 (1 件)

John D'Errico
John D'Errico 2018 年 6 月 8 日
In R2016 (not sure if it was a or b. I think b, but not really relevant, so will not check.) they introduced the capability to expand singleton dimensions for operations like this.
So now things like this work:
M = magic(3)
M =
8 1 6
3 5 7
4 9 2
M - mean(M)
ans =
3 -4 1
-2 0 2
-1 4 -3
Which is as you describe. Prior to the change, you needed to use bsxfun to do that, and before bsxfun existed, you had to expand the vector yourself, using a tool like repmat.
  1 件のコメント
James Tursa
James Tursa 2018 年 6 月 8 日
Implicit expansion introduced in R2016b.

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

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by