How to get array user input in 1 dialog box
11 次查看(过去 30 天)
显示 更早的评论
I have a set of code that creates 1 + 3 input dialog boxes to get parameters to run an analysis. I'd like to get the number of dialog boxes down to 1 + 1, where the requested inputs are aligned as 3 columns rather than 1 long series of inputs.
% get the number of levels
m = inputdlg('Enter the number of levels', 'Levels', [1 35], {'5'});
m = str2double(cell2mat(m));
%% get levels
prompt1 = repmat({'Level '}, 1, m);
for i = 1:m
prompt1{i} = [prompt1{i} int2str(i)];
end
levels = inputdlg(prompt1, 'Get Levels', [1 35] );
for i =1:m
lev(i) = str2double(levels{i});
end
levels = lev;
%% Get number of samples for each level
prompt2 = repmat({'N Level '}, 1, m);
for i = 1:m
prompt2{i} = [prompt2{i} int2str(i)];
end
reps = inputdlg(prompt2, 'Get Number of Samples', [1 35] );
for i =1:m
rep(i) = str2double(reps{i});
end
reps = rep;
%% Get runouts for each level
prompt3 = repmat({'Runouts Level '}, 1, m);
for i = 1:m
prompt1{i} = [prompt1{i} int2str(i)];
end
runouts = inputdlg(prompt3, 'Get Runouts', [1 35] );
for i =1:m
run(i) = str2double(runouts{i});
end
runouts = run;
%% Proceed with analysis after userinput
analyzeData(levels, reps, runouts);
0 个评论
采纳的回答
Jon
2023-3-20
If I am understanding what you would like to do I think this might work.
% Use single dialog box to collect all information, user enters data as
% space separated lists of numbers
% Build the input prompt strings
prompt = ["Enter the number of levels",...
"Enter level values as space separated list",...
"Enter number of samples as space separated list",...
"Enter runouts as space separated list"]
% Display the dialog
answer = inputdlg(prompt,'Experiment Design');
% convert to numerical values
numLevels = str2num(answer{1});
levels = str2num(answer{2});
reps = str2num(answer{3});
runouts = str2num(answer{4});
The main weakness of this is that it doesn't force the user to put in the required number of inputs for each subprompt. You could at least check after the user inputs the data that the number of elements of each response was correct and ask again if it isn't. Might be annoying to user though to get an error after they already typed in a lot of numbers.
6 个评论
Jon
2023-3-22
Oh and I should have given credit to @Shanmukha Voggu who gave the basic approach in https://www.mathworks.com/matlabcentral/answers/1636045-how-to-create-a-resizable-table-based-on-user-input-using-matlab-app-designer
which I then extended to answer your specific question
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Install Products 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!