MATLAB: Do I have Subscripted assignment dimension mismatch with imread(filename)

image analysis

Hello,
I am facing an issue with "imread" in a Loop for but I do not know where it Comes from. What I want to do is to Access multiple Images that are in a Folder and read These Images at each k of the Loop. But then the code always stops and can't read the Images. This error always Comes up: "Subscripted assignment dimension mismatch. Error in test2 (line 40) pic(k,:,:)=imread(filename); %Read the Image"
For your Information, I have calculated: size(imread(filename)), I am having the following answer: 1024 1024 3 Hereunder my code. Thanks a lot for your help 🙂
fullpath=fullfile('c:\','Users','Images');
startN=0;
endN=881;
steplength=1;
width=1024;
height=1024;
index=1;
x=500;
y=500;
% Load the image from the hard disk
for k=1:(endN-startN+1)
clear imageN; %clear the memory
imageN=int2str(k+startN-1);
if k+startN-1<10
filename=strcat(fullpath,'Test BTR000',imageN,'.jpeg');
elseif k+startN-1<100
filename=strcat(fullpath,'Test BTR00',imageN,'.jpeg');
elseif k+startN-1<1000
filename=strcat(fullpath,'Test BTR0',imageN,'.jpeg');
% elseif k+startN-1<10000
% filename=strcat(fullpath,'Test BTR',imageN,'.jpeg');
else
filename=strcat(fullpath,'Test BTR',imageN,'.jpeg');
end
pic(k,:,:)=imread(filename); %Read the image
end
% to find the scaling corresponding to the interferograms
for k=1:(endN-startN+1)
value(k)=double(pic(k,y,x));
end

Best Answer

I have just found out the solution, here is the code. It might help someone else:
fullpath=fullfile('c:\','Users','bbebey','Desktop','Projekts','WLI-PL','Matlab Auswertung','Auswertung mit CWT_numerical data','Images',filesep);
startN=0;
endN=881;
steplength=1;
width=1024;
height=1024;
index=1;
x=500;
y=500;
% Load the image from the hard disk
for k=1:(endN-startN+1)
clear imageN; %clear the memory
imageN=int2str(k+startN-1);
if k+startN-1<10
filename=strcat(fullpath,'Test BTR000',imageN,'.jpeg');
elseif k+startN-1<100
filename=strcat(fullpath,'Test BTR00',imageN,'.jpeg');
elseif k+startN-1<1000
filename=strcat(fullpath,'Test BTR0',imageN,'.jpeg');
% elseif k+startN-1<10000
% filename=strcat(fullpath,'Test BTR',imageN,'.jpeg');
else
filename=strcat(fullpath,'Test BTR',imageN,'.jpeg');
%Read the image
pictemp=imread(filename);
pic[k,1]=pictemp[x,y];
end
% find the scaling corresponding to the interferograms
for k=1:(endN-startN+1)
value(k)=double(pic[k,1]);
end