Prev: interp3 problems
Next: How do I pass out extra parameters using ODE23 or ODE45 from the MATLAB ODE suite?
From: Michael on 15 Apr 2010 04:48 I want to get the value from a matrix having only a non-integer element address without doing a simple roundoff. Example: Matrix(1,1) = 9; Matrix(1,2) = 5; Matrix(2,1) = 7; Matrix(2,2) = 0; I want to get the value at (1.2,1.7). I know the principle of bilinear interpolation and I know of the interp2 function, though it seems I'm a bit slow on the uptake today...
From: Rune Allnor on 15 Apr 2010 05:33 On 15 apr, 10:48, "Michael " <michael.schmittNOS...(a)bv.tum.de> wrote: > I want to get the value from a matrix having only a non-integer element address without doing a simple roundoff. > > Example: > Matrix(1,1) = 9; > Matrix(1,2) = 5; > Matrix(2,1) = 7; > Matrix(2,2) = 0; > > I want to get the value at (1.2,1.7). I know the principle of bilinear interpolation and I know of the interp2 function, though it seems I'm a bit slow on the uptake today... So you want somebody to read the docs, reshape the numbers to what INTERP2 can digest, and run the code for you? It's far more work writing the post than doing it yourself. And doing it yourself will save you from the inevitable ensuing abuse. Get a cup of strong coffee and have another go at it. Rune
From: Michael on 15 Apr 2010 06:53
Guess you're right, might've been a bit on the lazy side. Now here's the solution: [X,Y] = meshgrid([1;2],[1;2]); interpolatedValue = interp2(X,Y,Matrix,1.7,1.2,'bilinear'); The only thing you have to care about is not to mix up (row,col) coordinates with (x,y) coordinates as used by meshgrid and interp2. Sorry for opening this thread! |