MATLAB Answers

App Designer app property is saved as double although I enter strings

14 views (last 30 days)
Tim Koopman
Tim Koopman on 8 Feb 2020
Edited: Adam Danz on 8 Feb 2020
In App Designer I run into the issue of not being able to assign a string (or any other variable type) other than double to new properties I create.
This is my code (simplified):
properties (Access = public)
nameSave
end
% Button pushed function: Calculate
function CalculateButtonPushed(app, event)
app.nameSave(1,1) = "John"
app.nameSave(1,2) = "Peter"
end
I would now assume that nameSave is a 1x2 string array just like how it works in the normal editor. However, in App Designer, nameSave is a 1x2 double filled with [NaN,NaN] although I obviously assign strings to nameSave.
What is the mistake I am making?

  0 Comments

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 8 Feb 2020
Edited: Adam Danz on 8 Feb 2020
By default the property is initially defined to class=double.
Here are two solutions.
Set the property to a string array by placing the word string next to the property definition.
properties (Access = private)
nameSave string
Don't use indexing on the first assignment
app.nameSave = "John"; %now it's a string array!
app.nameSave(2) = "Mary";
If needed, you can use the following to determine whether nameSave is emtpy: isempty(app.nameSave)

  0 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!