필터 지우기
필터 지우기

how to repeat a section of code changing file parameters

조회 수: 1 (최근 30일)
Nakk Mungofa
Nakk Mungofa 2014년 3월 28일
댓글: Azzi Abdelmalek 2014년 4월 9일
i have a section of my code that reads an image from a file in a folder, it then processes that image and gives an output... i want the code to change the image file name at each cycle. for example; if image name is "image_1" it should then change to "image_2" and so on... this is the section of code so far:
% code
vid = videoinput('winvideo', 1);
set(vid, 'ReturnedColorSpace', 'RGB');
img = getsnapshot(vid);
pause(1.5);
imshow(img);
%// this is where image is saved
counter = 1;
baseDir = 'C:\Users\Nakk\Documents\zvanhasi\Number_Plate_Extraction\';
baseName = 'Image_';
newName = fullfile(baseDir, sprintf('%s%d.jpg', baseName, counter));
while exist(newName,'file')
counter = counter + 1;
newName = fullfile(baseDir, sprintf('%s%d.jpg', baseName, counter));
end
imwrite(img, newName);
%and then this is the part that reads image from file and process it
f=imread('Image_1.jpg'); % Reading image file.
%then some processing steps
so i want the
f=imread('Image_1.jpg');
to change to f=imread('Image_2'); f-imread('Image_3');
and so on....

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 3월 28일
for k=1:10
file=sprintf('Image_%d.jpg',k)
%do
end
  댓글 수: 2
Nakk Mungofa
Nakk Mungofa 2014년 4월 9일
hie thanks azzi but it didnt seem to work... i need the code to change each time i run it, the loop is just displayin " file = (Image_1)..." up to 10 in the command window...
Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 9일
I've inserted %do. replace it with your own code

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by