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
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!