Implicit matrix expansion correction

2 views (last 30 days)
Garima Sharma
Garima Sharma on 20 Jun 2017
Edited: Stephen23 on 25 Jan 2022
I have the following line of code (running in Matlab2016b), but which shows up with a "matrix dimensions must agree" error in Matlab2015a. How would I correct it? Thank you!
a=reshape(a(a ~= b(:,2)'),[],c);

Answers (2)

Guillaume
Guillaume on 20 Jun 2017
It would have been helpful if you'd provided more details such as the size of a, b and c. Most likely,
a = reshape(a(bsxfun(@ne, a, b(:, 2)'), [], c);
would solve the problem. If not, provide more details.
While you're at it rename these extremely meaningless variable names to something a lot more meaningful.
  1 Comment
Garima Sharma
Garima Sharma on 20 Jun 2017
Thank you. a is 11x21, b(:,2)' is 1x21, and c is 21.

Sign in to comment.


VBBV
VBBV on 25 Jan 2022
a = rand(11,21);
b = rand(21,1);
c = 21
a = reshape(a(a~=b.'),[],c)
There is no error with your code. Maybe it's version issue or check with any symbolic variables are present inside your a or b matrices.
  1 Comment
Stephen23
Stephen23 on 25 Jan 2022
"There is no error with your code. Maybe it's version issue..."
Implicit dimension expansion was introduced in R2016b:
The OP states that they were comparing R2016b with R2015a (which throws an error).

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!