Skip to content
Snippets Groups Projects
Verified Commit f164750a authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Old MATLAB compatibility fix

This is a partial revert of 4346903c. The
xlswrite function is actually not able to write XLS files on GNU/Linux and
macOS, and moreover its CSV fallback does not work with cell arrays.
parent 13c6cf86
No related branches found
No related tags found
No related merge requests found
...@@ -52,19 +52,29 @@ else ...@@ -52,19 +52,29 @@ else
end end
end end
if ~ispc && ~isoctave && matlab_ver_less_than('9.0')
% On GNU/Linux and macOS, with MATLAB < R2016a, “writeable” can’t write Excel files
% (and “xlswrite” can’t either)
warning('This version of MATLAB is too old and cannot create Excel files. The Occbin regimes will rather be written to a CSV file.')
filename=[OutputDirectoryName filesep xls_filename '.csv'];
else
filename=[OutputDirectoryName filesep xls_filename '.xls']; filename=[OutputDirectoryName filesep xls_filename '.xls'];
end
if isfile(filename) if isfile(filename)
delete(filename) delete(filename)
end end
if isoctave || (~ispc && matlab_ver_less_than('9.0')) if isoctave
% “writetable” and “array2table” don’t exist under Octave % “writetable” and “array2table” don’t exist under Octave
% On GNU/Linux and macOS, with MATLAB < R2016a, “writeable” can’t write Excel files
if isoctave && ~user_has_octave_forge_package('io') if isoctave && ~user_has_octave_forge_package('io')
error('The io package is required to write XLS files from Octave') error('The io package is required to write XLS files from Octave')
end end
xlswrite(filename, vertcat(Header, xlsmat)); xlswrite(filename, vertcat(Header, xlsmat));
elseif ~ispc && matlab_ver_less_than('9.0')
% Use a CSV file. See the comment above about filename.
% We don’t use xlswrite because its CSV fallback does not support cell-arrays.
writetable(array2table(xlsmat,'VariableNames',Header), filename);
else else
writetable(array2table(xlsmat,'VariableNames',Header), filename, 'Sheet', 'Regimes'); writetable(array2table(xlsmat,'VariableNames',Header), filename, 'Sheet', 'Regimes');
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment