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

1 回表示 (過去 30 日間)
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 件のコメント
Walter Roberson
Walter Roberson 2018 年 7 月 19 日
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 2018 年 7 月 19 日
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?

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2018 年 7 月 20 日

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 7 月 19 日
編集済み: Walter Roberson 2018 年 7 月 19 日
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 件のコメント
Image Analyst
Image Analyst 2018 年 7 月 20 日
You didn't read the FAQ, did you?
drummer
drummer 2018 年 7 月 20 日
ahhhhhhhhhhhh Image Analyst! Thank you very much! Declaring as a global variable worked!!!
Walter, thanks for everything!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDICOM Format についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by