MATLAB: Does IMAGESC produce an error when I am changing the parameter order

climerrorimageimagescMATLAB

I expect the following commands:
imagesc(rand(100),'Parent',h,[0 0.5])
imagesc(rand(100),[0 0.5],'Parent',h)
to give the same result. However, the second version does not work and produces an error:
??? Error using ==> image
Incorrect number of arguments specified
Error in ==> imagesc at 40
hh = image(varargin{:},'CDataMapping','scaled');

Best Answer

This is expected behavior. As displayed in the IMAGESC documentation the CLIM array should be passed as the last argument.
To understand what happens, view the IMAGESC code by executing the following at the MATLAB prompt:
type imagesc
When changing the the parameter order calling IMAGESC like:
imagesc(rand(100),[0 0.5],'Parent',h)
this leads to the following. Line 25 of IMAGESC cannot identify CLIM and processes line 40:
image(varargin{:},'CDataMapping','scaled');
which according to your example resolves in:
image(rand(100),[0 0.5],'Parent',h,'CDataMapping','scaled');
and apparently produces an error, because IMAGE does not no what to do with the second parameter ([0 0.5]). Furthermore CLIM is an AXES property and will not work inside the IMAGE command.
Use IMAGESC as suggested in the documentation or directly work with the IMAGE command, for example like:
h=axes('Clim',[0 0.5]);
image(rand(100),'Parent',h,'CDataMapping','scaled');