MATLAB: Access to files and variables in App Designer

access to fileapp designervariables

Hello, as a beginner with App Designer I would like to ask about problem with access to files and variables in App Designer. In my app I have, button for loading serie of images and from that function I get cell array of images called cell_dicom. I want to display images in UIAxes acoording to value of Slider component. But with my code I get error for this Slider component. Error says that I have undefined variable cell_dicom. So my first question is why app designer dont save/know this variable, when was defined in other function and how can I fix it? Second problem I have with access to folder with function imshow for Drop Down component. I want to imshow image from folder 'Slidy', but I get error that this folder dont exist althoug this folder 'Slidy' exists next to my application on my computer. Function of components looks like:
% Button pushed function: NastDICOMButton
function NastDICOMButtonPushed(app, event)
[File_Name, Path_Name,~ ] = uigetfile('*.dcm','MultiSelect','on')%Nacteni vstupnich dat
[s,z] = size(File_Name);
...
for i = 1:z
cell_dicom {1,i} = im2double(dicomread (File_Name(i,:)));
cell_dicom {1,i} = imadjust(cell_dicom {1,i}, stretchlim(cell_dicom {1,i}, 0), []); %Here create cell_dicom
end
end
% Value changed function: VyberablonuDropDown
function VyberablonuDropDownValueChanged(app, event)
value = app.VyberablonuDropDown.Value;
if ( value=='Frontální pohled na kmen - schéma pozic řezů altasu' )
imshow('Slidy\schema_rezu.png', 'Parent', app.UIAxes2); %According to app designer dont existing folder Slidy, but exists next to my app.mlapp
...
end
% Value changed function: SnmekSlider
function SnmekSliderValueChanged(app, event)
value = app.SnmekSlider.Value;
if ( value==1 )
imshow(cell_dicom{1,1},'Parent', app.UIAxes ) %Here dont know cell_dicom
...
end

Best Answer

"... I get an error for this Slider component. The error says that I have an undefined variable cell_dicom."
Each function has its own workspace and does not have access to variables in other workspaces / functions. If you want "cell_dicom" to be available in the SnmekSliderValueChanged() value-change function, you need to retreive it from somehwere.
From the NastDICOMButtonPushed() function, store the values of cell_dicom in your GUI using guidata() (see link). Then use guidata() to retreive that variable from SnmekSliderValueChanged().
" I get error that this folder dont exist although this folder 'Slidy' exists next to my application on my computer"
You may not be using the full path to the file. Try using the full path. You can also test that the file exists using exist(fullpath, 'file').