The code you show doesn't appear to be related to a GUI, so it's unclear how it relates to your question.
how does the image name (of the selected image) save itself in the workspace
Nothing saves itself. You have to explicitly store whatever information you want to keep in a variable.
In the code you show, if you want to keep the index of the random images you're using you have to store the output of randi and randperm rather than discarding them as soon as you don't need them:
files = dir('/Users/Documents/MATLAB/IR1/**/*.dcm')
num_files = numel(files);
chosen_singlefile = randi(num_files);
filename = files(chosen_singlefile).name;
image = dicomread(filename);
chosen_permutation = randperm(num_files);
for image_order = chosen_permutation
k = image_order
filename = files(k).name;
image = dicomread(filename);
end
Best Answer