update EditField from reading file data

I have a GUI developed with appdesigner. Default values are set for an EditField and two EditFields (numeric).
One of my callbacks reaads a data text file which may or maynot have values equal to the set default values above.
If they are different, I want to update the value in the EditFields. I have used app.TextNotes.Value = fgetl(fid); where TextNotes is the text editfield. I get the error:
Unable to perform assignment because dot indexing is not supported for variables of this type.
Error in BBW/ReadFileButtonPushed (line 172)
app.textNotes.Value=fgetl(fid); % textNotes
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 62)
newCallback = @(source, event)executeCallback(ams, ...
I am stuck, please help.

3 Kommentare

Walter Roberson
Walter Roberson am 9 Mai 2023
Either app or app.textNotes is empty, or not a graphics object, at that point in the code.
Put in a breakpoint at the line and run to there, and examine the values.
Michael
Michael am 9 Mai 2023
I have changed two lines to commenttn=fgetl(fid). The value is the updated text from the read operation.
later in the code (before the end of the callback) I have app.textNotes = commenttn. It is also correct. How ever, the EditField value does not change.
app.textNotes = commenttn
That would replace the textNotes property with the value in commenttn rather than updating the Value of a uitext or uiedit field.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Divyanshu
Divyanshu am 17 Mai 2023

0 Stimmen

Hi Michael,
I have designed a sample application which has three edit fields. It has one text and two numeric edit fields. Few things to consider:
  • A startup function is defined which sets the default values of numeric edit fields to ‘2’.
  • test.txt” is a sample file which holds a number.
  • A function ‘testFunc’ is called when the button is pushed and then based on the read value from file and default value of numeric field, text edit field value is updated.
methods (Access = private)
% Code that executes after component creation
function start(app)
app.EditField.Value = 2;
app.EditField2.Value = 2;
end
% Button pushed function: Button
function testFunc(app, event)
app.testString = fileread("test.txt");
if(app.testString == string(app.EditField.Value))
app.EditField3.Value = "Same";
else
app.EditField3.Value = "Not same";
end
end
end
Please refer the following documentation for more information on startup functions & tasks:

Kategorien

Mehr zu Data Type Identification finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2023a

Gefragt:

am 9 Mai 2023

Beantwortet:

am 17 Mai 2023

Community Treasure Hunt

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

Start Hunting!

Translated by