Not enough input arguments

I believe to properly have set up the function. I don't think to miss anything, but still keeps giving me the error of not enough input arguments.
function AxialView(object,eventdata,ImgAx,S_s,S_c,S,S_a,sno,sno_a,Rmin,Rmax,shand,stxthand)
if view == 'S'
S_s = S;
elseif view == 'C'
S_c = S;
end
view == 'A';
Img = ImgAx;
S = S_a;
sno = sno_a;
cla(hdl_im);
hdl_im = axes('position',[0,0.2,1,0.8]);
imshow(squeeze(Img(:,:,S,:)), [Rmin Rmax])
if sno > 1
shand = uicontrol('Style', 'slider','Min',1,'Max',sno,'Value',S,'SliderStep',[1/(sno-1) 10/(sno-1)],'Position', S_Pos,'Callback', {@SliceSlider, Img});
stxthand = uicontrol('Style', 'text','Position', Stxt_Pos,'String',sprintf('Slice# %d / %d',S, sno), 'BackgroundColor', [0.8 0.8 0.8], 'FontSize', SFntSz);
else
stxthand = uicontrol('Style', 'text','Position', Stxt_Pos,'String','2D image', 'BackgroundColor', [0.8 0.8 0.8], 'FontSize', SFntSz);
end
caxis([Rmin Rmax])
if sno > 1
set(stxthand, 'String', sprintf('Slice# %d / %d',S, sno));
else
set(stxthand, 'String', '2D image');
end
set(get(gca,'children'),'cdata',squeeze(Img(:,:,S,:)))
set (gcf, 'ButtonDownFcn', @mouseClick);
set(get(gca,'Children'),'ButtonDownFcn', @mouseClick);
end

5 Comments

The error comes to the line of Img=ImgAx;
which is completely unfair
@Stelios Fanourakis: how are you calling the function?
Stelios Fanourakis
Stelios Fanourakis on 12 Dec 2017
Edited: Stelios Fanourakis on 12 Dec 2017
@AxialView. It says it at the top
Stephen23
Stephen23 on 12 Dec 2017
Edited: Stephen23 on 12 Dec 2017
@Stelios Fanourakis: at the top you show us how you define the function, but not how it is called. I ask you to please show us how you are calling the function.
Basic ways of calling functions are explained in the introductory tutorials, which are highly recommended for all beginners:
This is the line code where I call the function AxialView:
VAxBtnhand = uicontrol('Style', 'pushbutton','Position', VAxBtn_Pos,'String','A', 'FontSize', BtnSz, 'Callback' , @AxialView);

Sign in to comment.

Answers (1)

Stephen23
Stephen23 on 12 Dec 2017
Edited: Stephen23 on 12 Dec 2017
Your comment shows that you have provided the function handle as a callback function to some GUI object. When you read the documentation for callback functions, it will inform you that by default only two arguments are provided to the callback function, which are called the source and event (commonly named src and evt inside the function definition).
Your function requires more than two input arguments - do you see the problem now?
If you wish to pass additional arguments then you will have to either:
  • Read the section "Passing Additional Input Arguments" in the documentation that I linked to above.
  • Use nested functions.
MATLAB does not just magically fill all of those input arguments with values.

Categories

Find more on Just for fun in Help Center and File Exchange

Asked:

on 12 Dec 2017

Edited:

on 12 Dec 2017

Community Treasure Hunt

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

Start Hunting!