MATLAB Answers

aldburg
0

Edit Field labels and edit field numeric loop

aldburg
さんによって質問されました 2017 年 12 月 15 日
最新アクティビティ Michal Dobai さんによって 編集されました 2017 年 12 月 16 日
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 件のコメント

Note that in general you can zip files and attach the zip
Thank you for the suggestion Walter, I will do that in the future.

サインイン to comment.

タグ

製品

1 件の回答

Answer by Michal Dobai on 16 Dec 2017
Edited by Michal Dobai on 16 Dec 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.

  0 件のコメント

サインイン to comment.



Translated by