saving files in .mat in another folder

3 次查看(过去 30 天)
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 个)

Kevin Holly
Kevin Holly 2022-1-7
编辑:Kevin Holly 2022-1-7
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

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by