MATLAB Answers


How to save matrix to workspace instead of plotting using imagesc function

Asked by Naz
on 25 Jun 2012

I don't understand how imagesc function works (scales), but my images plotted using via that function look better than using imshow. Is there any way to save the scaled image in the workspace instead of displaying it? I tried to debug built-in imagesc.m, but found nothing that scales data. If anyone knows how it's done, please, let me know.




No products are associated with this question.

1 Answer

Answer by Walter Roberson
on 25 Jun 2012
 Accepted answer

If M is your image, then

minM = min(M(:));
maxM = max(M(:));
scaledM = (M - minM) ./ (maxM - minM);

This will be in the range 0 to 1, so if you want to work with uint8 then uint8(scaledM .* 255)

  1 Comment

on 25 Jun 2012

Thank's Walter, works well for me.

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!