Loop code for images with x1, y1, z1 variables

hi all. i cannot solve this issue. briefly, i have a code for image manipulation, however i cannot solve putting it into a loop. for 7 photos in the images folder, i want to read it one by one and after manipulation i want to store the outputs in x1,x2,...x7 , y1,y2,...y7 , z1,z2,...z7. significant part of the code can be seen below.
thank you so much in advance.
for k=1:7
i = imread(sprintf('images/a%d.jpg',k));
.....
im = rgb2gray(i);
....
eval(['x' num2str(i)='double(im)']);
eval(['y' num2str(i)='x(:)']);
eval(['z' num2str(i)='hist(y)']);
end
....
i have also tried the code below with sprintf instead of num2str and yet it haven't worked either.
eval(sprintf('x%d = double(im)', i));
eval(sprintf('y%d = x%d(:)', i));
eval(sprintf('z%d = hist(y%d)', i));

 채택된 답변

Image Analyst
Image Analyst 2013년 12월 13일

0 개 추천

i has not been defined yet when you did:
i = imread(sprintf('images/a%d.jpg',i));
perhaps you meant
rgbImage = imread(sprintf('images/a%d.jpg', k));

댓글 수: 2

Adelante
Adelante 2013년 12월 13일
sorry i've misspelled it . in my code, correct line is:
i = imread(sprintf('images/a%d.jpg',k));
the main problem is in the loop.thank you
Image Analyst
Image Analyst 2013년 12월 13일
You don't want to create variables z1, z2, etc. See the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F Make an array instead. You also don't need to use eval() - I never ever use it or need to.

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

추가 답변 (0개)

태그

질문:

2013년 12월 13일

편집:

2013년 12월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by