Edit Field labels and edit field numeric loop
10 ビュー (過去 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 件のコメント
回答 (1 件)
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Interactive Control and Callbacks についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!