I want to create my own function in MATLAB which check some conditions but I don't know how to send handles in there. In the end, I want to print some text in the GUI from this other function. I can't use handles.t1 directly in this function because it is not accessible from within the function. How can I pass it there?
function y = check(tab)
if all(handles.tab == [1,1,1])
set(handles.t1, 'String', 'good');
else
set(handles.t1, 'String', 'bad');
end
end
Edit
After comment and first answer I decided to put whole callback where I call my function:
function A_Callback(hObject, eventdata, handles)
if handles.axesid ~= 12
handles.axesid = mod(handles.axesid, handles.axesnum) + 1;
ax = ['dna',int2str(handles.axesid)];
axes(handles.(ax))
matlabImage = imread('agora.jpg');
image(matlabImage)
axis off
axis image
ax1 = ['dt',int2str(handles.axesid)];
axes(handles.(ax1))
matlabImage2 = imread('tdol.jpg');
image(matlabImage2)
axis off
axis image
handles.T(end+1)=1;
if length(handles.T)>2
check(handles.T(1:3))
end
end
guidata(hObject, handles);
You'll need to use
guidatato retrieve thehandlesstruct that GUIDE automatically passes between callbacks. You'll also need a handle to thefigureto retrieve theguidataand we'll usefindallcombined with theTagproperty (below I've usedmytagas an example) to locate the GUI figure.If the input argument
tabis a handle to a graphics object within your figure, you can just callguidataon that to get thehandlesstructUpdate
In your update to your question, since you are calling
checkdirectly from a callback, simply pass the necessary variables to your function and then operate on them normallyAnd then from within your callback
Alternately, you could pass the entire
handlesstruct to yourcheckfunctionAnd then within your callback