MATLAB: Saving individual contents of struct into another folder other than the working directory

fullfilesave

Hello,
I have a struct file 'x'. I wish to store each content of the file as an indiviual '.mat' file in a sub folder of the name 'best'. The code is as follows. I recieve an error message of the following. How can I modify my code?
%% Main aim of the script is to load only specific files from a list of names provided in
%% 'rFile' and then store these files in a subfolder called 'Best'
% Creating a cell consisting of names extracted fom 'rfile'
s = rFile.ImName;
% Adding an extention to each name in s
files = string(s) + '_avg_crd.mat';
n = numel(files);
% Creating the folder the files need to be saved
subfolder = fullfile(folder,'Best');
x = struct([]);
% the loop selects and stores in struct 'C.files_avg', only those files from the folder,
% that match the names with extension stored in 'files'.
% This list from C.files_avg is then saved with the same names into a subfolder of the original folder,
% called Best
for ii = 1:n
files_avg (ii) = fullfile(folder, files(ii));
C(ii).files_avg = load(files_avg{ii});
x {ii,2}= C(ii).files_avg;
x {ii,1}= files(ii);
matname = char;
matname = fullfile(subfolder, files(ii));
save(matname, x{ii,2}) ;
end
'Error using save
Must be a string scalar or character vector.'

Best Answer

You can only save complete variables. You can assign to a variable and save that.
Remember that things saved need to appear as variables in mat files so it would not work to save a part of a variable.