How to arrange input fields straight below each other using inputsdlg?

10 Ansichten (letzte 30 Tage)
I'm using the Matlab Add-On "inputsdlg: Enhanced Dialog Box" to catch information of participants. The dialog box works fine but looks messy, because the input fields are not arraged straight below each other since the promptheadlines have different lenghts.
So, what can I do that all the input fields start at the same width position of my dialog box window?
Using the regular "inputdlg" is not an option because I have a dropdown field in the dialog box.
Code:
% Add-On "inputsdlg" must be installed, otherwise code wont run!
name = 'Participantdata'; % Titel
prompt = {'ParticipantID';'FirstName';'LastName';'Age';'Sex'}; % Collected Data
formats = struct('type', {}, 'style', {}, 'items', {}, 'format', {}, 'limits', {}, 'size', {});
formats(1,1).type = 'edit';
formats(1,1).format = 'integer';
formats(1,1).limits = [0 1000];
formats(1,1).size = [200 20];
formats(2,1).type = 'edit';
formats(2,1).style = 'edit';
formats(2,1).format = 'text';
formats(2,1).size = [200 20];
formats(3,1).type = 'edit';
formats(3,1).style = 'edit';
formats(3,1).format = 'text';
formats(3,1).size = [200 20];
formats(4,1).type = 'edit';
formats(4,1).format = 'integer';
formats(4,1).limits = [1 150];
formats(4,1).size = [200 20];
formats(5,1).type = 'list';
formats(5,1).style = 'popupmenu';
formats(5,1).items = {'m','f'};
formats(5,1).size = [200 20];
defaultanswers = {0, 'NaN', 'Nan', 1, 1};
[answer, canceled] = inputsdlg(prompt, name, formats, defaultanswers);
Output:

Akzeptierte Antwort

Bora Eryilmaz
Bora Eryilmaz am 12 Jan. 2023
You won't get perfect alignment, but you can pad the prompt strings with empty spaces:
prompt = {...
'ParticipantID'; ...
'FirstName '; ...
'LastName '; ...
'Age '; ...
'Sex '}; % Collected Data
  1 Kommentar
Brezelbayer
Brezelbayer am 12 Jan. 2023
Thanks! Well, I guess for a perfect alignment it's better to create an app with a GUI than using inputsdgl.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Display and Presentation finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by