Steve on Image Processing with MATLAB

Image processing concepts, algorithms, and MATLAB

MATLAB arithmetic expands in R2016b

Earlier this summer, I was writing some color-space conversion code. At one point in the code, I had a Px3 matrix calledRGB, which contained P colors, one per row. I also had a 1x3 vector,v. I needed to multiply each column ofRGBby the corresponding element ofv, like this:

RGB_c = [RGB(:,1)*v(1) RGB(:,2)*v(2) RGB(:,3)*v(3)];

But since I was using an internal developer build of MATLAB R2016 (released on September 14), I didn't type the code above. Instead, I typed this:

RGB_c = RGB .* v;

In R2016a and older MATLAB releases, that line of code produced an error:

>> RGB_c = RGB .* vError using.*Matrix dimensions must agree.

In the new release, though, MATLABimplicitly expandsthe vectorvto be the same size as the matrixRGB然后执行elementwise multiplication. I say "implicitly" because MATLAB does not actually make an in-memory copy of the expanded vector.

To read all about this change in MATLAB matrix arithmetic, head over toLoren's Art of MATLAB blogand read myguest postabout it.




Published with MATLAB® R2016b

|
  • print
  • send email

Comments

To leave a comment, please clickhereto sign in to your MathWorks Account or create a new one.