Edit Field labels and edit field numeric loop

4 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2017-12-15
Note that in general you can zip files and attach the zip
aldburg
aldburg 2017-12-15
Thank you for the suggestion Walter, I will do that in the future.

请先登录,再进行评论。

回答(1 个)

Michal Dobai
Michal Dobai 2017-12-16
编辑:Michal Dobai 2017-12-16
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.

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by