Function Button error : Not enough input arguments.

Hello
I have the following button:
%--------------Button-----------------------
btLinePropsPos = [0.81,0.08,0.12,0.1];
btLineprops = com.mathworks.mwswing.MJButton('Done');
btLineprops.setBorder([]);
btLineprops.setBackground( java.awt.Color.black);
btLineprops.setForeground(java.awt.Color.red)
btLineprops.setFont(java.awt.Font('Vivaldi',java.awt.Font.PLAIN,30))
btLineprops.setCursor(java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
btLineprops.setFlyOverAppearance(true);
btLineprops.setToolTipText('Create Truss');
[dummy,btContainer] = javacomponent(btLineprops,[0 0 1 1]); %#ok
set(btContainer, 'Units','Norm', 'Position',btLinePropsPos);
set(btLineprops, 'ActionPerformedCallback',@DoneCallback);
set(btContainer, 'Units','Norm', 'Position',btLinePropsPos);
-----------------------------------------
Then I click it : the followiing funtion should be done :
function DoneCallback(hObject, eventdata, handles)
global S
switch S
case 'Sloped Truss'
axes(handles.axes2);
imshow('shadedTruss.jpg');
case 'Vertical Truss'
axes(handles.axes2);
imshow('shadedTruss.jpg');
end
------------------------------
I am having the following error when axes(...) is reached :
*Error using Truss>DoneCallback (line 113)
Not enough input arguments.*
axes2 is created from outside, the problem here seems to be with handles because the variable S was a handles than when I turned it to global it worked but the error wasn't solved
any help ?
thank you

1 comentario

Rayane
Rayane el 25 de Dic. de 2013
If I erase axes(handles.axes2), the image appear in a new figure that opens independently from the project ! I want the image to remain in the same project ...

Iniciar sesión para comentar.

 Respuesta aceptada

MATLAB never automatically passes handles to callbacks. GUIDE goes to the trouble of adding the handles parameter by setting the callback to a string that when executed fetches the handles and passes the two automatic parameters and the handles as well.
If you know that the button is on the same figure as the main gui, then code it with only two parameters, and then as the first thing in the callback do
handles = guidata(hObject);

4 comentarios

Thank you
1 Problem solved , Solution was :
global h
h=handles;
-----------------------------------
switch S
case 'Sloped Truss'
axes(h.axes2);
imshow('shadedTruss.jpg');
case 'Vertical Truss'
axes(h.axes2);
imshow('shadedTruss.jpg');
end
-----------------------------
1 Problem Remained : Opening the image in a new figure not in the axes
Rayane
Rayane el 26 de Dic. de 2013
case 'Vertical Truss'
imshow('shadedTruss.jpg','parent',h.a2);
This Did work without any error
but the axes isn't appearing !
As some temporary diagnostic code, before the imshow() call, add
fprintf(1, 'axes2 is %.16f, handle? %f, figure %.16f\n', h.axes2, ishandle(h.axes2), ancestor(h.axes2, 'figure'));
and after the imshow() add
drawnow()
and then run and tell us what the output is.
Rayane
Rayane el 26 de Dic. de 2013
Thanks :)
Result :
a2 is 30.0292968750000000, handle? 1.000000, figure 201.0070800781250000
---------------------------------------
Everything works smoothly but nothing appears ! I'm thinking of creating the axes within the code and not from outside because it doesn't appear at all ... but I forgot how to define it 0_0 !
Any help?
a2=uicontrol(....) ?

Iniciar sesión para comentar.

Más respuestas (1)

Rayane
Rayane el 26 de Dic. de 2013
Problem solved Thank you
the problem was with hAxes
I erased and everything worked correctly
but an empty figure still appears !
here's the code
---------------------
img=imread('shadedTruss.jpg');
[M, N, C]=size(img);
set(h.a2,'units','pixels','visible','on','Position',[37 -280 N+237 M+1000],'box','off','tickdir','out','XLimMode','manual','XLim',[0 10],'YLimMode','manual','YLim',[0 1],'ydir','reverse');
imshow(img,'parent', h.a2);
set(h.a2, 'ButtonDownFcn',@buttonDownCallback)

1 comentario

The position in pixels of -280 is asking to position a corner of the axes outside of the figure.

Iniciar sesión para comentar.

Categorías

Más información sobre Function Creation en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 25 de Dic. de 2013

Comentada:

el 26 de Dic. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by