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

 채택된 답변

Jon
Jon 2023년 3월 20일

0 개 추천

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
Jon 2023년 3월 22일
Were you able to solve your problem? Was this helpful?
Ojaswi
Ojaswi 2023년 3월 22일
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
Jon
Jon 2023년 3월 22일
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.
Ojaswi
Ojaswi 2023년 3월 22일
This works really well and I can directly integrate it into my code. Thanks!
Jon
Jon 2023년 3월 22일
Excellent! Glad this helped.
Jon
Jon 2023년 3월 22일
which I then extended to answer your specific question

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품

릴리스

R2022b

태그

질문:

2023년 3월 20일

댓글:

Jon
2023년 3월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by