Edit Field labels and edit field numeric loop

조회 수: 4 (최근 30일)
aldburg
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
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