MATLAB Linear vector + string vector = array works in r2017a but not in r2016a

I am using the + operator in my r2017a version to sum a line vector and a row vector to give me an array.

A = [1 2]

B = [1; 2]

C = A + B = [2 3; 3 4]

I tried to run my code on another computer with r2016a version but it doesn't work.

How can I just execute this command?

+3


source to share


2 answers


MATLAB introduced a new function in r2016b that automatically expands matrices to the required size when performing arithmetic operations. You can read about it here . Hence your code doesn't work in r2016a. The way to do it in r2016a is



C = bsxfun(@plus, A, B);

      

+3


source


i does not have r2017 and this operation is logically flawed i think you wanted to do it

C=[A+B(1);A+B(2)]

      

and it is definitely faster than functions



you can use to loop for higher values

for i=1:size(b,1)        
C=[A+B(i);A+B(i)];
end

      

0


source







All Articles