GUIDE: how to share variables of a local function on its .m file to another callback button?

1 view (last 30 days)
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
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 .
drummer
drummer on 19 Jul 2018
Walter, I'd like val to be the currently slider value which the user would choose the best slice. Then, I'd like to use val in the Uniformity test. But even using handles, how would it be available to test_callback?

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 20 Jul 2018

More Answers (1)

Walter Roberson
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
drummer
drummer on 20 Jul 2018
ahhhhhhhhhhhh Image Analyst! Thank you very much! Declaring as a global variable worked!!!
Walter, thanks for everything!

Sign in to comment.

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!