MATLAB Answers

Why do my EditField / TextArea not get updated?

조회 수: 1(최근 30일)
Blanca R.
Blanca R. 26 Oct 2020
댓글: Blanca R. 27 Oct 2020
Hello everyone,
I am currently writing an app with AppDesigner to plot some variables.
I have a ListBox containing the variable names I have listed in a table. In that table I also have the path information of the variable.
I am trying to display that path information in a TextArea or in an EditField, however they stay empty.
I've tried to solve this with these lines in the ListBox-function
function VariablesListBoxValueChanged(app, event)
app.VariablesListBox.ItemsData = 1:length(app.VariablesListBox.Items);
SelectNum = app.VariablesListBox.Value;
load s; % s is the table which I already loaded with another button
SelectPath = s.Y(SelectNum).Path;
set(app.VariableTextLabel, 'Text', SelectPath);
app.VariablePathTextArea.Value = SelectPath
save SelectNum;
save SelectPath;
and with these ones in the PushButton-function
function ShowButtonPushed(app, event)
load s;
load SelectNum;
load SelectPath;
set(app.VariableTextLabel, 'Text', SelectPath);
but nothing seemes to be working.
I am very helpful for every piece of advice. Many thanks in advance!

  댓글 수: 0

댓글을 달려면 로그인하십시오.

채택된 답변

Mario Malic
Mario Malic 26 Oct 2020
편집: Mario Malic 27 Oct 2020
The save command saves your workspace into file called SelectNum, maybe without file format, I can't verify this now.
You can have SelectPath as a property of the application, declare it at the beginning and change the line in the first callback to
app.SelectPath = s.Y(SelectNum).Path;
In the second callback, this should do it.
function ShowButtonPushed(app, event)
app.VariablePathTextArea.Value = app.SelectPath % This updates the text area (white space)
% app.VariableTextLabel.Text = SelectPath % This updates label (description)

  댓글 수: 3

Blanca R.
Blanca R. 27 Oct 2020
Hello and thanks for your answer.
I've declared the variable SelectPath in a properties-block,
properties (Access = private)
changed the line "app.SelectPath = s.Y(SelectNum).Path;" in the first callback and in the second I have now these lines (I think an "app." was missing in yours as Matlab was showing a warning)
app.VariablePathTextArea.Value = app.SelectPath;
app.VariableTextLabel.Text = app.SelectPath;
I can see in the command window that "app.SelectPath" has the right value, however there's nothing showing up in the Edit/TextArea fields :/
Mario Malic
Mario Malic 27 Oct 2020
Correct, I forgot to add the "app." part.
Did you put the correct handle to the component? If you click on the component, you can see its name in component browser. Is the component editable, are you sure you aren't writing in white font? It may sound silly, but these commands should work.
Does below outputs the correct value?
Blanca R.
Blanca R. 27 Oct 2020
Somehow, it works if I write the lines in the first callback! I also saved the table data of the table "s" as a property of the application. And it works without problems for the features EditField, TextArea as well as in a Label. I still don't know why it doesn't work in a PushButton-Callback, but I can work with this!
The code for displaying the path-information of a table and updating it when selecting a new item in a ListBox look now like this:
function VariablesListBoxValueChanged(app, event)
app.VariablesListBox.ItemsData = 1:length(app.VariablesListBox.Items);
SelectNum = app.VariablesListBox.Value; % SelectNum = index of the selected item
app.SelectPath = app.s.Y(SelectNum).Path; % get the path information out of the table called "s"
% display the information every time a new item of the ListBox gets selected
app.VariablePathTextArea.Value = app.SelectPath; % display it in a TextArea
app.VariablePathLabel.Text = app.SelectPath; % display it in a Label
app.VariablePathEditField.Value = app.SelectPath; % display it in an EditField
Thanks very much for your help!!

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by