how to create a directory?

7 ビュー (過去 30 日間)
rikki kumar
rikki kumar 2018 年 4 月 12 日
コメント済み: Walter Roberson 2018 年 4 月 12 日
how to create a directory where i have to store images and later read that folder and subplot all images in 1 figure window without overlapping
plz give replies..need help to finish project

採用された回答

Walter Roberson
Walter Roberson 2018 年 4 月 12 日
%create a directory
tdir = tempname();
mkdir(tdir);
numimg = 10;
imagenames = cell(numimg, 1);
%store some images in there
for K = 1 : numimg
randimg = randi([0 255], 32, 32, 3);
imgnames{K} = fullfile( tdir, sprintf('image_%03d.png', K) );
imwrite(randimg, imgnames{K});
end
pause(20); %"later"
%read that folder
images = cell(numimg, 1);
for K = 1 : numimg
imgname = imagenames{K};
if ~exist(imgname, 'file')
fprintf('somehow a file went missing: "%s"\n', imgname);
images{K} = [];
else
images{K} = imread(imgname);
end
end
%subplot all of them in one figure without overlapping
image4 = cat(4, images{:});
montage(image4);
Note:
If your only reason for reading them back in is to display them, then you can skip from "read that folder" onwards and instead use just
montage(imagenames);
  2 件のコメント
rikki kumar
rikki kumar 2018 年 4 月 12 日
thank u for reply sir i tried this code..its working well with 1 image which i took ...but when i am taking images from the directory created its not working .....could u tell me what changes i have to make in that case this s directory i created
Walter Roberson
Walter Roberson 2018 年 4 月 12 日
https://www.mathworks.com/matlabcentral/answers/393879-how-to-display-sub-images-which-is-stored-in-folder-without-overlapping#answer_314683
cd('image8');
dinfo = dir('*.png');
filenames = {dinfo.name};
montage(filenames);
Or perhaps you would prefer
cd('image8');
montage((1:64) + ".png") %requires R2017a or later
or even
montage(reshape(1:64,8,8).' + ".png")
... Remember, we do not know what order the pictures are "supposed" to be in.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by