saving files in .mat in another folder

1 回表示 (過去 30 日間)
Giuseppe Anastasio
Giuseppe Anastasio 2022 年 1 月 7 日
編集済み: Kevin Holly 2022 年 1 月 7 日
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 件のコメント
Ben McMahon
Ben McMahon 2022 年 1 月 7 日
Look at the documentation for movefile.

サインインしてコメントする。

回答 (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 Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by