APP DESIGNER. How can I use a variable generated by one function in another funcion?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have this function in App Designer:
function LoadButtonPushed(app, event)
% Display uigetfile dialog
[fn p] = uigetfile('*.dcm','MultiSelect','on'); %#ok
dicom_files = {};
for file = 1:length(fn)
str_temp = string(fn(file));
dicom_files = [dicom_files dicomread(str_temp)]; %#ok
end
end
And I want to be able to use the variable dicom_files on this function:
function Slices_value(app, event)
value = app.SlicesSpinner.Value;
if exist(value, 'var') == 1
imshow(uint8(dicom_files{value}), [], 'parent', app.ImageAxes);
end
end
How should I do it? The code does not recognise dicom_files in the second function
댓글 수: 0
채택된 답변
Mohammad Sami
2020년 7월 8일
You need to create an app property dicom_files to store the values in.
Change to code view, click the property button, click public property. Type the name of the property dicom_files.
After that you can change your two functions to update this value
function LoadButtonPushed(app, event)
% Display uigetfile dialog
[fn p] = uigetfile('*.dcm','MultiSelect','on'); %#ok
dicom_files = {};
for file = 1:length(fn)
str_temp = string(fn(file));
app.dicom_files = [app.dicom_files dicomread(str_temp)]; %#ok
end
end
function Slices_value(app, event)
value = app.SlicesSpinner.Value;
if exist(value, 'var') == 1
imshow(uint8(app.dicom_files{value}), [], 'parent', app.ImageAxes);
end
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!