Bozmaje
Bozmaje

Reputation: 75

Matlab: How to save Excel files to the specific folder rather than current folder?

I have the below code:

for p = 1:numel(C)
    filename = C{p}{1,2};
    if ~isempty(filename{:})
        sprintf('%s.xlsx',filename{:})
        writetable(C{p},sprintf('%s.xlsx',filename{:}))
    end
end

I want to save all excel files generated in this code to "C:\AZAR" instead of the current folder. I know I must use fullfile and add a path to the filename but since I'm not really familiar with Matlab codes I didn't how to do it.

Upvotes: 0

Views: 121

Answers (1)

JAC
JAC

Reputation: 466

Your guess of using fullfile is correct. Within the if/end block build the file name including the directory more or less as follows:

fname = fullfile('C:\', 'AZAR', sprintf('%s.xlsx',filename{:});
writetable(C{p},fname);

HTH

Upvotes: 1

Related Questions