필터 지우기
필터 지우기

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

조회 수: 18 (최근 30일)
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?

채택된 답변

Adam Danz
Adam Danz 2020년 2월 8일
편집: Adam Danz 2020년 2월 8일
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
hzh
hzh 2021년 8월 31일
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 2021년 8월 31일
편집: Adam Danz 2021년 8월 31일
> 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.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by