フィルターのクリア

Add multiple plots in the same graph

5 ビュー (過去 30 日間)
george korris
george korris 2021 年 4 月 14 日
回答済み: yanqi liu 2022 年 2 月 24 日
Hello everyone i have the next code which reads multiple pictures from the same folder and in the end plots the fft of the lines of the pics and saves all the fft plots one by one. Is there a way to make show all the ffts of the pics in the same graph and save it? I tried hold on but it just plots in the last pic of the first image the second image.My code is this: ( the plot i want to draw for all my images in the same graph.
clc;
clear all;
% Specify the folder where the files live.
myFolder = 'folder';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder);
uiwait(warndlg(errorMessage));
myFolder = uigetdir(); % Ask for a new one.
if myFolder == 0
% User clicked Cancel
return;
end
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.jpg'); % Change to whatever pattern you need.
% Get a list of all files in the folder, and its subfolders, with the desired file name pattern.
%filePattern = fullfile(myFolder, '**/*.png'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
img = imread(fullFileName);
%img = imread('1.jpg');
img = imcrop(img)
imshow(img)
figure, imshow(img_rot)
figure, contourf(prof_img_rot)
f = figure;
%figure
loglog(fft_prof(1:128))
hold on
File = sprintf('0.3%0.1f.png', k);
% Write to disk.
exportgraphics(f,fullfile(myFolder,File));
end
hold off
close all
  4 件のコメント
dpb
dpb 2021 年 4 月 15 日
Then take all the calls to figure out of the loop and only create a figure, saving the handle to it before the loop.
Then set hold on and plot all results to the one axes.
For multiple FFTs, this could end up really messy-looking; you might want to look at the waterfall plot to be able to distinguish one from another.
george korris
george korris 2021 年 4 月 17 日
thank you

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

回答 (1 件)

yanqi liu
yanqi liu 2022 年 2 月 24 日
clc;
clear all; close all;
% Specify the folder where the files live.
myFolder = fullfile(matlabroot,'toolbox/images/imdata');
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder);
uiwait(warndlg(errorMessage));
myFolder = uigetdir(); % Ask for a new one.
if myFolder == 0
% User clicked Cancel
return;
end
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.jpg'); % Change to whatever pattern you need.
% Get a list of all files in the folder, and its subfolders, with the desired file name pattern.
%filePattern = fullfile(myFolder, '**/*.png'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
figure;
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
img = imread(fullFileName);
%img = imread('1.jpg');
%img = imcrop(img);
%imshow(img);
%figure, imshow(img_rot)
%figure, contourf(prof_img_rot)
%f = figure;
%figure
% one image to be saved that has all the subsequent plots
fft_prof = fft2(double(img(:,:,1)));
loglog(fft_prof(1:128))
hold on
%File = sprintf('0.3%0.1f.png', k);
% Write to disk.
%exportgraphics(f,fullfile(myFolder,File));
end
Now reading /MATLAB/toolbox/images/imdata/baby.jpg Now reading /MATLAB/toolbox/images/imdata/car1.jpg Now reading /MATLAB/toolbox/images/imdata/car2.jpg Now reading /MATLAB/toolbox/images/imdata/car_1.jpg Now reading /MATLAB/toolbox/images/imdata/car_2.jpg Now reading /MATLAB/toolbox/images/imdata/car_3.jpg Now reading /MATLAB/toolbox/images/imdata/car_4.jpg Now reading /MATLAB/toolbox/images/imdata/colorCheckerTestImage.jpg Now reading /MATLAB/toolbox/images/imdata/eSFRTestImage.jpg Now reading /MATLAB/toolbox/images/imdata/flamingos.jpg Now reading /MATLAB/toolbox/images/imdata/foggyroad.jpg Now reading /MATLAB/toolbox/images/imdata/foggysf1.jpg Now reading /MATLAB/toolbox/images/imdata/foggysf2.jpg Now reading /MATLAB/toolbox/images/imdata/foosball.jpg Now reading /MATLAB/toolbox/images/imdata/football.jpg Now reading /MATLAB/toolbox/images/imdata/greens.jpg Now reading /MATLAB/toolbox/images/imdata/hallway.jpg Now reading /MATLAB/toolbox/images/imdata/hands1.jpg Now reading /MATLAB/toolbox/images/imdata/hands2.jpg Now reading /MATLAB/toolbox/images/imdata/indiancorn.jpg Now reading /MATLAB/toolbox/images/imdata/llama.jpg Now reading /MATLAB/toolbox/images/imdata/lowlight_1.jpg Now reading /MATLAB/toolbox/images/imdata/lowlight_2.jpg Now reading /MATLAB/toolbox/images/imdata/micromarket.jpg Now reading /MATLAB/toolbox/images/imdata/office_1.jpg Now reading /MATLAB/toolbox/images/imdata/office_2.jpg Now reading /MATLAB/toolbox/images/imdata/office_3.jpg Now reading /MATLAB/toolbox/images/imdata/office_4.jpg Now reading /MATLAB/toolbox/images/imdata/office_5.jpg Now reading /MATLAB/toolbox/images/imdata/office_6.jpg Now reading /MATLAB/toolbox/images/imdata/parkavenue.jpg Now reading /MATLAB/toolbox/images/imdata/peacock.jpg Now reading /MATLAB/toolbox/images/imdata/sevilla.jpg Now reading /MATLAB/toolbox/images/imdata/sherlock.jpg Now reading /MATLAB/toolbox/images/imdata/strawberries.jpg Now reading /MATLAB/toolbox/images/imdata/trailer.jpg Now reading /MATLAB/toolbox/images/imdata/wagon.jpg Now reading /MATLAB/toolbox/images/imdata/yellowlily.jpg
hold off
Warning: Negative data ignored
% close all

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by