How to run m-files automatically ?

Hi,
I have collection of images to analyze using matlab. I made m-file code to analyze one image at a time, but it takes considerable time as there are hundreds of images to run.
Is there anyway to call the files in the folder and run one at a time automatically, without me designating the file name one by one?
Thank you very much for help.

 采纳的回答

Matt Fig
Matt Fig 2012-9-1
编辑:Matt Fig 2012-9-2
D = dir('*.jpg');
for ii = 1:length(D)
% Put your processing code here. Call image names as below...
fprintf('Processing image named %s\n',D(ii).name);
end

5 个评论

Thank you very much
Why are you using fprintf() inside imread()??? That's just used to write stuff to the command line or a file. Just use D(ii).name in the imread() directly.
fullFileName = fullfile(folder, D(ii).name); % Folder is pwd unless you specify otherwise.
fprintf('About to read in %s...\n', fullFileName);
theImage = imread(fullFileName);
fprintf('Successfully read in %s\n', fullFileName);
Thank you for the quick reply. I found what was wrong.
I am confused. Who is using FPRINTF inside IMREAD?
Taehyung was but then after I said that, he went back and edited his code to delete it and say "Thank you very much"

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2012-9-2

1 个投票

3 个评论

And when you read this section of the FAQ, I suggest to read the rest also.
You could use the foll code
folder_cont = dir('C:\Users\*.jpg');
nsize = size((folder_cont),1);
for i = 1:nsize
str=strcat('C:\Users\',D(i).jpg);
im=imread(str);
%%do the processing of the image here
end
Thank you very much for the help!

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by