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

4 Ansichten (letzte 30 Tage)
Erik Vabo Vatsvaag
Erik Vabo Vatsvaag am 29 Jun. 2020
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!

Antworten (2)

Uttkarsh Jha
Uttkarsh Jha am 29 Jun. 2020
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 am 29 Jun. 2020
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

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by