In Octave I would like to save a struct to a textfile where the name of the file is decided during the runtime of the script. With my approach I always get an error:
expecting all arguments to be strings.
(For a fixed filename this works fine.) So how to save a struct to a file using a variable filename?
clear all;
myStruct(1).resultA = 1;
myStruct(1).resultB = 2;
myStruct(2).resultA = 3;
myStruct(2).resultB = 4;
variableFilename = strftime ("result_%Y-%m-%d_%H-%M.mat", localtime(time()))
save fixedFilename.mat myStruct;
% this works and saves the struct in fixedFilename.mat
save( "-text", variableFilename, myStruct);
% this gives error: expecting all arguments to be strings