Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

Index exceeds matrix dimensions, error problem

1 view (last 30 days)
shashikant khandagale
shashikant khandagale on 20 Jan 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
clc;
clear all;
tic; q=0;
f=dir('*.jpg');
srcfile=dir('D:\Project Work\Phase-2\Reconstruction\dice\*.jpg');
files={srcfile.name};
for eleimg = 1 : numel(files)
%filename = strcat('C:\Users\Admin\Documents\MATLAB\dice\',srcfile(eleimg).name);
eleimg1 = imread(files{eleimg});
currentimage2=rgb2gray(eleimg1);
look{q+eleimg,1}=currentimage2;
% figure, imshow(currentimage2);
[sx,sy] = size(currentimage2);
Nx=7;Ny=7;d=450;
cx=23.7;cy=15.6;f=20;L=2;
px=0.34;py=0.45;
shx=ceil((px * f * sx)/(d*cx));
shy=ceil((py * f * sy)/(d*cy));
look{q+eleimg,2}=shx;
look{q+eleimg,3}=shy;
grid_image=zeros(shx*(Nx-1)+sx,shy*(Ny-1)+sy,L*Nx*Ny);
grid_overlap_number=zeros(shx*(Nx-1)+sx,shy*(Ny-1)+sy,L*Nx*Ny);
end
for k=1:Nx*Ny*L
v1=uint16(cell2mat(look(k,2)));
v2=uint16(cell2mat(look(k,3)));
grid_image(v1:sx,v2:sy,k)=uint16(cell2mat(look(k,1)));%[1:sx,1:sy]
grid_overlap_number(v1:sx,v2:sy,k)=ones(sx,sy);
end
tic;
for l=1:L
overlap_image=sum(grid_image(:,:,Nx*Ny*(l-1)+1:Nx*Ny*l),3);
overlap_number=sum(grid_overlap_number(:,:,Nx*Ny*(l-1)+1:Nx*Ny*l),3);
slice_image= rdivide(overlap_image,overlap_number);
figure,imshow(uint8(slice_image));
end
toc;
when I run code the programme shows me
Index exceeds matrix dimensions.
Error in finalserialcode (line 28) v1=uint16(cell2mat(look(k,2)));
I cant figure it out.any one help?

Answers (1)

Niels
Niels on 20 Jan 2015
Your variable look has a length of eleimg.
You are trying to access some value between 1 and Nx*Ny*L (which is equal to 98). I suspect that eleimg is smaller than 98.

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!