Save Function and uisave are not working properly.

3 visualizaciones (últimos 30 días)
Sheran Bhattacharyya
Sheran Bhattacharyya el 4 de Jul. de 2020
Editada: dpb el 5 de Jul. de 2020
Can you please tell me why the following codes are not working?
The functional form of save is not working right, especially when I am trying to specify a name of the file while saving it.
I have tried to extract the filenames from the user defined names using the following code.
Filename = Name(~isspace(Name));
Then I have tried using the following codes to save the file.
Filename = [Filename{:} '.mat'];
uisave({Name, x, y ,z}, Filename);
Another way I tried...
save(Filename, {Name, x, y, z});
The save function is working when the filename specified is static such as
save('all_variables.mat', {Name, x ,y ,z});
Please tell me what am I doing wrong here. What should I do to save the variables along with the user specified dynamic names? And why am I getting an error message in the above pictures? Should it not be saving the variables dynamically instead of showing an error message dialog box?

Respuestas (1)

dpb
dpb el 4 de Jul. de 2020
Editada: dpb el 5 de Jul. de 2020
Syntax issues...
>> Name='A long File Name'; % just something to follow your lead...
>> Name=Name(~isspace(Name)); % hadn't ever thought of doing this, but does kill embedded blanks
>> dir AlongFileName.* % prove it wasn't already there...
No matches for pattern 'AlongFileName.*'.
% here's the problem -- the variable name must be char() string; you had the variable itself
>> save(Name,'x')
>> dir AlongFileName.* % now there is a file there
AlongFileName.mat
>> whos -file AlongFileName.mat % whos there -- that's the variable from the workspace here...
Name Size Bytes Class Attributes
x 9x3x3 648 double
>>
Similar issues with uisave (altho I've never used it). It is different from save however, in that it does accept/require the cell array of variables to have more than one; save will NOT accept that form--
>> save(Name,{'x','xx'})
Error using save
Must be a string scalar or character vector.
>>
Instead, it uses a list of variable names...
>> whos x*
Name Size Bytes Class Attributes
x 9x3x3 648 double
xx 1x3 24 double
xy 4x5 40 char
>> save(Name,'x','xx')
>> whos -file AlongFileName.mat
Name Size Bytes Class Attributes
x 9x3x3 648 double
xx 1x3 24 double
>>

Categorías

Más información sobre Cell Arrays en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by