Make edit fields visible/invisible based on length of an array

2 ビュー (過去 30 日間)
Erik Vabo Vatsvaag
Erik Vabo Vatsvaag 2020 年 6 月 29 日
回答済み: Erik Vabo Vatsvaag 2020 年 6 月 29 日
Hello,
I am programming an app which includes to edit fields that creates arrays and based on the length of these array I want to display a new set of edit fields.
The solution I found for this problem is to make a lot of if statements when the length of the array changes.
Is there a more efficient way? I dont know if it is possible to group edit fields in some way to make this easier.
Thank you for helping!

回答 (2 件)

Uttkarsh Jha
Uttkarsh Jha 2020 年 6 月 29 日
Hey Erik,could you share your matlab app screenshot/code snippet?
That way the community may be able to assist you better.

Erik Vabo Vatsvaag
Erik Vabo Vatsvaag 2020 年 6 月 29 日
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
x2HS1EditFieldLabel matlab.ui.control.Label
hs1x2 matlab.ui.control.EditField
x1HS1EditField_2Label matlab.ui.control.Label
hs2x1 matlab.ui.control.EditField
HSEditFieldLabel matlab.ui.control.Label
HSEditField matlab.ui.control.EditField
x2HS2EditFieldLabel matlab.ui.control.Label
hs2x2 matlab.ui.control.EditField
end
properties (Access = private)
XCoord %Description
HS %Description
end
methods (Access = private)
% Value changed function: XCoordinatesEditField
function XCoordinatesEditFieldValueChanged(app, event)
app.XCoord = str2double(strsplit(event.Value));
app.HS = str2double(strsplit(app.HSEditField.Value));
if(length(app.XCoord) > 0 && length(app.HS)>0)
app.hs1x1.Enable = true;
app.hs1x1.Editable = true;
app.hs1x1.Visible = true;
app.x1HS1EditFieldLabel.Text = ['a at x = ', num2str(app.XCoord(1)), ', Hs = ', num2str(app.HS(1))];
end
if(length(app.XCoord) >= 2 && length(app.HS)>0)
app.hs1x2.Enable = true;
app.hs1x2.Editable = true;
app.hs1x2.Visible = true;
x2HS1EditFieldLabel.Text ="a at x = " + num2str(app.XCoord(2)) + ", Hs =" + num2str(app.HS(1));
end
if(length(app.HS) >= 2 && length(app.XCoord)>0)
app.hs2x1.Enable = true;
app.hs2x1.Editable = true;
app.hs2x1.Visible = true;
x1HS1EditField_2Label.Text = "a at x = " + num2str(app.XCoord(1)) + ", Hs = " + num2str(app.HS(2));
end
if(length(app.HS) >=2 && length(app.XCoord)>=2)
app.hs2x2.Enable = true;
app.hs2x2.Editable = true;
app.hs2x2.Visible = true;
x2HS2EditFieldLabel.Text = "a at x = " + num2str(app.XCoord(2)) + ", Hs = " + num2str(app.HS(2));
end
end
% Value changed function: HSEditField
function HSEditFieldValueChanged(app, event)
app.HS = str2double(strsplit(event.Value));
app.XCoord = str2double(strsplit(app.XCoordinatesEditField.Value));
if(length(app.XCoord) > 0 && length(app.HS)>0)
app.hs1x1.Enable = true;
app.hs1x1.Editable = true;
app.hs1x1.Visible = true;
app.x1HS1EditFieldLabel.Text = "a at x = " + num2str(app.XCoord(1)) + ", Hs = " + num2str(app.HS(1));
end
if(length(app.XCoord) >= 2 && length(app.HS)>0)
app.hs1x2.Enable = true;
app.hs1x2.Editable = true;
app.hs1x2.Visible = true;
x2HS1EditFieldLabel.Text ="a at x = " + num2str(app.XCoord(2)) + ", Hs =" + num2str(app.HS(1));
end
if(length(app.HS) >= 2 && length(app.XCoord)>0)
app.hs2x1.Enable = true;
app.hs2x1.Editable = true;
app.hs2x1.Visible = true;
x1HS1EditField_2Label.Text = "a at x = " + num2str(app.XCoord(1)) + ", Hs = " + num2str(app.HS(2));
end
if(length(app.HS) >=2 && length(app.XCoord)>=2)
app.hs2x2.Enable = true;
app.hs2x2.Editable = true;
app.hs2x2.Visible = true;
x2HS2EditFieldLabel.Text = "a at x = " + num2str(app.XCoord(2)) + ", Hs = " + num2str(app.HS(2));
end
end
end

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by