MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by P
on 25 Jan 2013

I am supposed to do the bilinear interpolation without using imresize or interp. I am getting the error 'Index exceeds matrix dimensions' The padding was to avoid that.

{ f300=imread('Chrono');

fbilin(1:3:2769,1:3:2109)=f300(1:923,1:703);

f300=padarray(f300,[4 4],'replicate','both');

for j=1:3:2109

for i=1:3:2769 f11=f300(i,j+2); f12=f300(i,j+2); f21=f300(i+2,j); f22=f300(i+2,j+2); fbilin(i+1,j+1)=(f11*((i+2)-(i+1))*((j+2)-(j+1))+... f21*((i+1)-(i))*((j+2)-(j+1))+... f12*((i+2)-(i+1))*((j+1)-(j))+... f22*((i+1)-(i))*((j+1)-(j)))./((i+2)-(i))*((j+2)-(j)); end end

subplot(2,3,5), imagesc(fbilin), title('Chronometer Bilinear'); }

*No products are associated with this question.*

Answer by Matt J
on 25 Jan 2013

Edited by Matt J
on 25 Jan 2013

Accepted answer

Use DBSTOP to halt execution at the point where the error occurs. Check the values of the indices at that point. Also check the size of the (supposedly padded) arrays.

Show 5 older comments

Matt J
on 25 Jan 2013

Well, one thing should be clear. If the size of the array is 931, you should probably not be running i up to 2769, and similarly for j. Where did these numbers come from anyway?

## 1 Comment

## Image Analyst

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/59927#comment_125147

Click edit (to the upper left). Put a blank line before your code. Then highlight all your code and click {}Code icon above to format your code properly.