saving files in .mat in another folder

1 vue (au cours des 30 derniers jours)
Giuseppe Anastasio
Giuseppe Anastasio le 7 Jan 2022
Modifié(e) : Kevin Holly le 7 Jan 2022
Hello
I have 30 files with this name in a folder: IM0, IM1 and so on. I want to save them with their corrispective names in another folder in mat files. How can I do?
Thanks
  1 commentaire
Ben McMahon
Ben McMahon le 7 Jan 2022
Look at the documentation for movefile.

Connectez-vous pour commenter.

Réponses (1)

Kevin Holly
Kevin Holly le 7 Jan 2022
Modifié(e) : Kevin Holly le 7 Jan 2022
I am going to assume that you are reading image files and then trying to save them in another folder as mat files.
%Select folder containing files
uiwait(msgbox('Select folder you want to save','Select folder'))
folder = uigetdir; %Alternatively, you can insert the filepath here
files = dir(fullfile(folder,'IM*'))
%Assuming those are image files you are reading, you can read the first one
%as shown below
variable = imread(fullfile(folder,files(1).name))
%Select directory where you want to save files.
uiwait(msgbox('Select folder where you want to save files','Select Save Directory'))
savedir = uigetdir; %Alternatively, you can insert the filepath here
%If you want to save the first file
save(fullfile(savedir,files(1).name),variable)
%You can use a for loop to go through the different files
for i=1:length(files)
save(fullfile(savedir,files(i).name,variable)
end
%load and saving together assuming those are image files
for i=1:length(files)
variable = imread(fullfile(folder,files(i).name))
save(fullfile(savedir,files(i).name,variable)
end

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by