Saving files in App Designer

3 次查看(过去 30 天)
Tajana Lusetic
Tajana Lusetic 2019-12-6
回答: Riya 2025-2-26
Hi, I am trying to save my document and I want to save my Table variable as the name I wrote in my EditField
savein=uigetdir(Name of the location);
str=strcat(savein, {'/'}, app.EditField.Value);
newstr=char(str);
Table = strjoin(app.Clasification.Data)'
newName = input (app.EditField.Value,"s")
S.(newName) = Table
save([newstr '.mat'],'-struct','S')
And I get Invalid field Name: ' '
Please help

回答(1 个)

Riya
Riya 2025-2-26
Hi,
I understand that you are encountering an error while trying to set the variable name of “Table” to match the “EditField” value. This happens because “app.EditField.Value” may be empty or contain spaces, special characters, or numbers at the beginning, making it an “invalid structure field name”.
In MATLAB, Field names, like variable names, must begin with a letter, can contain letters, digits, or underscore characters, and are case sensitive.
To fix this, you can modify the field name to make sure it is valid. You can also use “matlab.lang.makeValidName” function which converts it to a valid name by replacing invalid characters with underscores and ensuring it does not start with a number.
newName = matlab.lang.makeValidName(strtrim(app.EditField.Value));
For more information about Generating field names from Variables, please refer to the following documentation:
Thanks!

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by