Array dimensions must match for binary array op

4 views (last 30 days)
Hello, I got a problem with this error: "Array dimensions must match for binary array op", the problem is that I used to use the trial version of matlab and my code works, but now I use the licensed version and it throw me a lot of errors like that when It used not to do it. Can someone explain this?

Accepted Answer

Walter Roberson
Walter Roberson on 30 Mar 2017
The trial version would have been R2017a probably. But the licensed version might have been R2016a or earlier.
One of the changes in R2016b was to automatically do the equivalent of bsxfun in some cases. For example if you had
A = (1:5)';
B = [10 20 30];
then in versions up to R2016a, A+B would be an error because arrays of size 5 x 1 could not be added to arrays of size 1 x 3. But as of R2016b, the situation would be treated as being like
bsxfun(@plus, A, B)
automatically replicating data to produce the answer
11 21 31
12 22 32
13 23 33
14 24 34
15 25 35
Your code accidentally used this feature and did something in the trial version, but then you moved over to an earlier version without the feature and the code failed.
For example your code might have X + Y but X might be a row vector and Y might be a column vector of the same length. In earlier versions that would be an error; from R2016b onwards it has been defined to do something. It might not be what you want done, but it does something.
  2 Comments
Ricardo Olvera
Ricardo Olvera on 30 Mar 2017
Thank you so much :) that was the problem, and I already solved it.
Saiful Haqiqi Hassan
Saiful Haqiqi Hassan on 17 Dec 2018
I am using r2018a. and still encountered this problem.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!