Azzera filtri
Azzera filtri

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

18 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Adam Danz
Adam Danz il 8 Feb 2020
Modificato: Adam Danz il 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)
  2 Commenti
hzh
hzh il 31 Ago 2021
properties (Access = private)
nameSave string
This is really the worst syntax I have ever seen in my life. Took me an hour to figure out how to properly declare the property to be a string array. Very counterintuitive.
properties (Access = private)
nameSave = ""
should have been the one used
Adam Danz
Adam Danz il 31 Ago 2021
Modificato: Adam Danz il 31 Ago 2021
> This is really the worst syntax I have ever seen in my life
I doubt it, but I feel your frustration.
> Took me an hour to figure out how to properly declare the property to be a string array
I'm sorry this answer didn't perfectly address whatever you were looking for and that you had to invest some of your own valuable time to figure out a solution that makes sense to you.
I took some time to find this page below so you can get more familiar with the available syntaxes for declaring properties.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by