GUIDE: how to share variables of a local function on its .m file to another callback button?
1 view (last 30 days)
Show older comments
Hello fellows. This questions is about using GUIDE.
Here's the problem: I have a function @callbackslider nested with another function (showDicom), which the input is a DICOM file to see along the slices. The function showDicom is called in a callback button.
These functions are in the showDicom.m file.
I'd like to use the slice number (from @callbackslider) information to use in another function (also with its own .m file) which is called within another callback button.
.m
function showDicom(x, handles)
acquisition = squeeze(x);
[row, col, z] = size(acquisition);
figure (1)
imagesc(acquisition(:,:,1));
colormap jet;
title('Transverse');
sld = uicontrol('Style', 'Slider', 'SliderStep', [1/94 1], 'Value',1,...
'Min', 1, 'Max', 95, 'Callback', @callbackslider01);
function callbackslider01(hObject, eventdata)
val = hObject.Value;
figure (1);
imagesc(acquisition(:,:,val));
title(num2str(val));
colormap jet;
end
end
Now, as I said, I want to use the val variable in another callback button, which calls the function Uniformity.m:
function test_Callback(hObject, eventdata, handles)
% hObject handle to Uniformity (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
f = msgbox('Look for the best slice, then press OK','test');
drawnow
waitfor(f);
Uniformity(dicom(:,:,val)); %function to run the test
I've extensively tried to use handles and guidata, but it didn't work. Thanks in advance.
2 Comments
Walter Roberson
on 19 Jul 2018
val would be a particular reading of the slider value as of the time the callbackslider01 ran. Is that particular reading required (for example for consistency with the image display), or would it be acceptable to fetch the current value of the object? Such as by saving sld into handles and then accessing sld.Value in test_Callback .
Accepted Answer
More Answers (1)
Walter Roberson
on 19 Jul 2018
Edited: Walter Roberson
on 19 Jul 2018
In showDicom after assigning to sld, do
handles.sld = sld;
guidata(hObject, handles);
Then
function test_Callback(hObject, eventdata, handles)
% hObject handle to Uniformity (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~isfield(handles, 'sld')
uiwait( msgbox('You must load data first') );
return;
end
f = msgbox('Look for the best slice, then press OK','test');
drawnow
waitfor(f);
val = max(1, min( round( handles.sld.Value ), size(dicom,3) ) );
Uniformity(dicom(:,:,val)); %function to run the test
This leaves open the question of how dicom got into test_Callback.
7 Comments
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!