error with function save (Unknown command option)

Hello, I have a problem when I use the save function but I can not find my error (I checked my variables and they are correct):
my code :
for i=1 : Number_of_pages
liste_de_index = Main_Table.Lbl == liste_de_labels(i);
Main_Table_filtered =Main_Table(liste_de_index,1:7);
Main_Table(liste_de_index,:) = [];
save(strcat(Name_Excel,'_table_',num2str(i),'.mat'),'Main_Table_filtered');
warning('off','MATLAB:xlswrite:AddSheet');
clearvars liste_de_index
end
and the command windows send :
Error using save
Unknown command option.
Error in Filter_text_file_and_create_Excel (line
125)
save(strcat(Name_Excel,'_table_',num2str(i),'.mat'),'Main_Table_filtered');
somebody knows ?

 Risposta accettata

I never try to do that much on one line. What happens if you split it up into two lines:
fileName = sprintf('%s_table_%d.mat', Name_Excel, i);
save(fileName, 'Main_Table_filtered');
Do you still get an error? If so, what is it and on which line? And, what does this give you if you type it in the command window:
>> which -all save

6 Commenti

it does not work :
test = sprintf('%s_table_%d.mat', Name_Excel,i)
test =
--_--\Output_files\MARINVENT\GNSS_Main_table_1.mat
K>> save(test,'Main_Table_filtered')
Error using save
Unknown command option.
Of the moves when I put: which -all save I got :
which -all save
built-in (C:\Program Files\MATLAB\R2015b\toolbox\matlab\general\save)
save is a Java method % Shadowed com.mathworks.services.Prefs method
C:\Program Files\MATLAB\R2015b\toolbox\matlab\codetools\+matlab\+desktop\+editor\@Document\Document.m % Shadowed matlab.desktop.editor.Document method
save is a Java method % Shadowed com.mathworks.mde.editor.MatlabEditor method
save is a Java method % Shadowed com.mathworks.matlab.api.editor.Editor method
C:\Program Files\MATLAB\R2015b\toolbox\matlab\winfun\@COM\save.m % Shadowed COM method
C:\Program Files\MATLAB\R2015b\toolbox\simulink\simulink\@slxPackager\save.p % Shadowed slxPackager method
C:\Program Files\MATLAB\R2015b\toolbox\idelink\extensions\ticcs\@ccsdebug\save.m % Shadowed ccsdebug method
C:\Program Files\MATLAB\R2015b\toolbox\sl3d\sl3d\@vrworld\save.m
Any idea ?
I did some testing and the problem would come from the Main_Table_filtered variable, yet it's only a 3335 * 7 table containing double and char
Does Name_Excel truly begin with a '-' s is shown in your sample output? If so then MATLAB would try to interpret it as a command line option. Ensure your filename does not begin with '-'. For example,
test = sprintf('.\\%s_table_%d.mat', Name_Excel,i)
Also look into using fullfile() and cd or pwd.
The problem came from the middle score in the name "Name_Excel"
I doubt it. I use underscores in variable names often and there is never a problem. It was probably some other error, like the value of Name_Excel started with a dash like Walter suggested.

Accedi per commentare.

Più risposte (1)

Tao Zhou
Tao Zhou il 2 Apr 2020
When I had a big data to save I came in this problem too.

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by