Returning both chosen and not chosen elements
Show older comments
Hello, I currently have a popup list where I can choose the filenames of files that I want to manually do something with. I am able to use the indices to returned from listdlg to find the names of the files that I want to work with, however; I need the output to also include the NaN's for the files that I did not choose. For example if I chose the first and third element in the list I would want manual_val = ['name of file 1' 'NaN' 'name of file 2']. This is what I have so far!
%% Select folder with all the data in it
if exist('dataDir')~=1
dataDir = uigetdir(pwd);
end
%looks for any files ending in .out
dataFiles = dir([dataDir, '/*.csv']);
%get all file names from the chosen folder
fname_total = [];
for k = 1:length(dataFiles)
fname = dataFiles(k).name;
fname_total = [fname_total; fname];
end
fname_total = cellstr(fname_total);
%Choose graphs for manual entry
manual = input('Are there any graphs you want to input manually? ');
if manual == 1
manual_idx = listdlg('PromptString', 'Choose Files to Analyze', ...
'ListString',fname_total,'SelectionMode','multiple');
manual_val = fname_total(manual_idx);
else
manual_val = {'none'};
end
Accepted Answer
More Answers (1)
Adam Danz
on 16 Mar 2022
0 votes
Adapt this to suit your needs
list = {'Red','Yellow','Blue',...
'Green','Orange','Purple'};
[indx,tf] = listdlg('ListString',list);
selection = repmat("NaN",size(list));
selection(indx) = list(indx)
% RESULTS after selecting 2nd and 3rd options
selection =
1×6 string array
"NaN" "Yellow" "Blue" "NaN" "NaN" "NaN"
Categories
Find more on App Building 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!