ディレクトリ 変更 ループ

12 views (last 30 days)
Ukasu
Ukasu on 17 Jan 2020
Answered: Kenta on 17 Jan 2020
日付ごとのフォルダがあり、フォルダごとに同じ作業を繰り返したいのですが、どうすればいいですか。
たとえばA,B,Cという3つのディレクトリがあり,下のようにそれぞれのディレクトリで同じ作業を行いたいです。
sdir = ['A','B','C'];
for n=1:3
cd sdir(n)
% 何かしらの作業。例えば、
I=dir('*.jpg');
size(I);
end

Accepted Answer

Kenta
Kenta on 17 Jan 2020
sdir = ['a','b','c'];
for n=1:3
cd(sdir(n))
I=imread('onion.png');
size(I)
cd ../
end
こんにちは、この例だと、cd ../でディレクトリをもとに戻し、さらにcdで、フォルダに入り、作業...という流れですれば可能です。

More Answers (0)

Community Treasure Hunt

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

Start Hunting!