Edit Field labels and edit field numeric loop

24 Ansichten (letzte 30 Tage)
aldburg
aldburg am 15 Dez. 2017
Bearbeitet: Michal Dobai am 16 Dez. 2017
I have an app that when one inputs a numerical value n, the callback will make n number of edit field labels and edit field input boxes. Is there a reason why the .mlapp format is not accepted as an uploadable file? I cost copied the script and saved it as a .m format.
I know it should start something like:
For i=1:value
%something I can't figure out
end
  4 Kommentare
Walter Roberson
Walter Roberson am 15 Dez. 2017
Note that in general you can zip files and attach the zip
aldburg
aldburg am 15 Dez. 2017
Thank you for the suggestion Walter, I will do that in the future.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Michal Dobai
Michal Dobai am 16 Dez. 2017
Bearbeitet: Michal Dobai am 16 Dez. 2017
This might be one way to do it:
First, you have to create new properties to hold handles of newly created controls:
TypeOfPlyEdidFields = matlab.ui.control.EditField %list of handles to dynamicaly generated edit fields
TypeOfPlyLabels = matlab.ui.control.Label %list of handles to dynamicaly generated labels
An then callback will look like this:
% Value changed function: NumberofPliesLaminasEditField
function Number_of_Plies(app, event)
value = app.NumberofPliesLaminasEditField.Value;
% delete all labels and edit fields
delete(app.TypeOfPlyLabels);
delete(app.TypeOfPlyEdidFields);
% save initial Y position
yPos = app.NumberofPliesLaminasEditField.Position(2);
% create new labels and edit fields.
for ind=1:value
% new label with it's properties
app.TypeOfPlyLabels(ind) = uilabel(app.TypesofUniquePliesTab);
app.TypeOfPlyLabels(ind).HorizontalAlignment = 'right';
app.TypeOfPlyLabels(ind).Text = 'Type of Ply';
app.TypeOfPlyLabels(ind).Position = [4 yPos-ind*22 148 22];
% new edit field with it's properties
app.TypeOfPlyEdidFields(ind) = uieditfield(app.TypesofUniquePliesTab, 'numeric');
app.TypeOfPlyEdidFields(ind).HorizontalAlignment = 'right';
app.TypeOfPlyEdidFields(ind).ValueDisplayFormat = '%.0f';
app.TypeOfPlyEdidFields(ind).Position = [164 yPos-ind*22 168 22];
end
end
Few more things:
  • Make sure you set limits to 'NumberofPliesLaminasEditField' You don't want allow your user to create hundreds of edit boxes (and if you do, something is probably wrong with this design :) )
  • Make sure you set 'RoundFractionalValues' property to 'on', because you don't want any decimal numbers as input.
  • Do you really need to do it this way? You should maybe consider using only one edit field with List Box.
  • If you do want to do it this way, maybe better solution would be creating maximum number of edit fields in StartupFcn and set their 'Visible' property to 'Off' by default. Then in your callback you can simply set first n edit fields to visible.
If you need more help with this, or something isn't clear enough for you, Leave a comment here, I will try to help you.

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by