MATLAB: Code not working in function but working in command line line by line

matlab function not working

i am writing a matlab function to produce a matching gray scale image. code is working in command line when i run it line by line but not running as a function and giving errors
too many input arguments
Error in imagesc (line 18)
hh =
image(varargin{1},'CDataMapping','scaled');
Error in image (line 19)
imagesc(j);
i am new to matlab and unable to understand.
function code is:
function image(grayLevel)
I = [255,255,0,0;255,255,0,0;0,0,255,255;0,0,255,255];
j = repmat(I,64);
i = 16;
m = 32;
while (i<256)
while(i<=m)
for k = 1:256
j(i,k) = grayLevel;
end
i = i+1;
end
i = i +16;
m = i+16;
end
imagesc(j);
end
any help or suggestions?

Best Answer

The problem is your function name:
function image(...)
Do NOT call your function image, because image is the name of a very important MATLAB function image which is called by imagesc and yet will not work now because you have redefined the name by calling your own function with that name. You will have to restart or clear to get rid of your redefined image function from memory.
Tip: always use which to check if a variable/function name is already used, e.g.:
which image
Related Question