How to get array user input in 1 dialog box

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);

 Accepted Answer

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 Comments

Were you able to solve your problem? Was this helpful?
This wasn't what I was looking for, sorry. As you said it doesn't force the user to input the right number of elements or keep the correct order for each set of conditions. If there is a way to build a custom dialog box that will be a way to do what I require
I have attached a little MATLAB app (App Designer App) that I think does what you are asking. The user enters the number of levels in an edit field. The app then creates a table for the user to fill out with the number of rows matching the number of levels the user has supplied. When the user has completed filling out the table they press the analyze button to retrieve the test specifications and run the analysis.
This works really well and I can directly integrate it into my code. Thanks!
Excellent! Glad this helped.
which I then extended to answer your specific question

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products

Release

R2022b

Asked:

on 20 Mar 2023

Commented:

Jon
on 22 Mar 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!