MATLAB Answers

Problem getting error while trying to save .mat file in every folder

4 views (last 30 days)
sam moor
sam moor on 22 May 2017
Commented: sam moor on 24 May 2017
I have 44 folders and I have a matlab script which runs for loop for every folder and save .mat file. But when I save .mat file inside the for loop, the matlab file doesn't save inside every folder but save in main folder. I want to save the mat file in every folder that I am running my script but it is not working. Is there any method to save .mat file in every folder of my for loop?

Accepted Answer

Stephen Cobeldick
Stephen Cobeldick on 22 May 2017
Edited: Stephen Cobeldick on 22 May 2017
You need to tell MATLAB the absolute or relative path of the directory where you want to save those files, something like this (you can fill in the missing data yourself):
for k = 1:N
...
k_path = ...
k_name = ...
k_full = fullfile(k_path,k_name);
save(k_full,...)
end
In any case, how to process a sequence of files is covered in the documentation and this forum (and folders uses exactly the same methods):
etc etc
  3 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by