code not working in function but working in command line line by line

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?

 採用された回答

Stephen23
Stephen23 2017 年 5 月 6 日
編集済み: Stephen23 2017 年 5 月 6 日

1 投票

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Images についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by