using eval with 2 variables

조회 수: 16 (최근 30일)
Alexandra Bilanska
Alexandra Bilanska 2015년 1월 24일
답변: Alexandra Bilanska 2015년 1월 25일
Hi I´m having a problem with this code:
L11 = imread('ocidoiris\001l.bmp');
L12 = imread('ocidoiris\001l.bmp');
L13 = imread('ocidoiris\001l.bmp');
L14 = imread('ocidoiris\001l.bmp');
L15 = imread('ocidoiris\001l.bmp');
frameNumber=1;
frame=1;
while frameNumber<2
while frame<6
NAME = sprintf('L%d%d',frameNumber,frame)
I=eval(sprintf('%s',NAME));
%I=eval(sprintf('L%d%d', frameNumber, frame));
I=im2double(I);
all I need is a result L11 L12 L13 L14 L15 but I need variable framenumber and frame for another for loop and for putting pictures that are converted from L11 to RGB, CMY to different folders... You can see, I´m using it here:
baseFileName = sprintf('00%dL%00%d.bmp', frameNumber, frame);
baseFileName2 = sprintf('00%d/L',frameNumber);
fullFileName = fullfile('OCI/',newdir, baseFileName2, baseFileName);
Can you help me with this problem? Thanks

채택된 답변

Geoff Hayes
Geoff Hayes 2015년 1월 24일
Alexandra - why not avoid using eval altogether and just store your images in a 1x5 cell array which you can then iterate over without having to worry about variable names that are dependent upon the frame number and frame. Something like
maxFrame = 5;
maxFrameNumber = 1;
frameData = cell(maxFrameNumber,maxFrame);
frameData{1,1} = imread('ocidoiris\001l.bmp');
frameData{1,2} = imread('ocidoiris\001l.bmp');
frameData{1,3} = imread('ocidoiris\001l.bmp');
frameData{1,4} = imread('ocidoiris\001l.bmp');
frameData{1,5} = imread('ocidoiris\001l.bmp');
atFrame = 1;
atFrameNumber = 1;
while atFrameNumber<=maxFrameNumber
atFrame = 1;
while atFrame<=maxFrame
I = frameData{atFrameNumber,atFrame};
% do your work with I
% save to file
% increment atFrame
atFrame = atFrame + 1;
end
% increment atFrameNumber
atFrameNumber = atFrameNumber + 1;
end
You should still be able to do what you want without the troublesome eval calls (which make debugging problems - like this one - a challenge!).

추가 답변 (1개)

Alexandra Bilanska
Alexandra Bilanska 2015년 1월 25일
Thanks, your code worked . I changed a small mistake in my code and it worked too.. Thanks :)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by