MATLAB: Error using save function in app designer

app designerMATLABsavestructures

Hello,
I have the following line of code in app designer:
save(data_filepath, '-struct','app.data');
where "app.data" is a structure of different types of variables that I would like to save to "data_filepath".
When I try to execute this line I receive the following error:
Error using save
The argument to -STRUCT must be the name of a scalar structure variable.
if I save app.data in a different structure (see following code), I no longer receive the previous error:
data_struct = app.data;
save(data_filepath, '-struct','data_struct');
Can you please tell me why is the error given in the first case?
Thank you.

Best Answer

This is not an official response, but some quick exploration would suggest that the use of dot notation is not allowed when passing in a structure. It appears to only accept the root structure. For example, this works
var.A = randi(1000,100,2);
var.B = randi(1000,100,2);
save('structSave.mat','-struct','var');
This does not even though var.A is still a structure
var.A.cat = randi(1000,100,2);
var.B = randi(1000,100,2);
var.A.new = 'testSub';
save('structSave.mat','-struct','var.A');
It's clearly capable of doing it, as you showed by assigning app.data to a new variable and saving that variable. I'll add this as an enhancement request.
Related Question