Thread Subject: Interpolation of matrix

Subject: Interpolation of matrix

From: Ben

Date: 8 Nov, 2007 14:30:22

Message: 1 of 5

Hi there,

I'm trying to perform some operations on a matrix - I have a 20x20
matrix that I've got to remove some rows from the top, and re-generate
lines at the bottom to leave the matrix the same size as it was.

So, say I have a 10x10 matrix, I remove the top row. What I now want to
do is generate a row between the row at the bottom, and the one above
it, that I can put in to keep it 10x10.

I've looked at interp2, and it sort of seems to do what I want, e.g
running interp2(Matrix) gives me a 19x19 matrix with an interpolated row
between each. Is there any way to point interp2 at a matrix, with row
vector 9, and get it to return a 1x10 matrix containing the interpolated
row between row vectors 9 and 10, that I can just add to the first matrix?

I believe interp2 can sort-of do this, using Xi and Yi, but that appears
to be more related to generating an interpolated value from two data
points, not two rows?

Anyone have any advice?

Thanks,

Ben

Subject: Interpolation of matrix

From: PB

Date: 8 Nov, 2007 21:04:18

Message: 2 of 5

Den Thu, 08 Nov 2007 14:30:22 +0000 skrev Ben:

> Hi there,
>
> I'm trying to perform some operations on a matrix - I have a 20x20
> matrix that I've got to remove some rows from the top, and re-generate
> lines at the bottom to leave the matrix the same size as it was.
>
> So, say I have a 10x10 matrix, I remove the top row. What I now want to
> do is generate a row between the row at the bottom, and the one above
> it, that I can put in to keep it 10x10.
>
> I've looked at interp2, and it sort of seems to do what I want, e.g
> running interp2(Matrix) gives me a 19x19 matrix with an interpolated row
> between each. Is there any way to point interp2 at a matrix, with row
> vector 9, and get it to return a 1x10 matrix containing the interpolated
> row between row vectors 9 and 10, that I can just add to the first
> matrix?
>
> I believe interp2 can sort-of do this, using Xi and Yi, but that appears
> to be more related to generating an interpolated value from two data
> points, not two rows?
>
> Anyone have any advice?
>
> Thanks,
>
> Ben

Does this help?

a=magic(3);
a(:,3)=[] % remove last row
ix=1:0.5:2;
[xi,yi]=meshgrid(ix)
y=interp2(a,xi,yi)


/PB

Subject: Interpolation of matrix

From: Ben

Date: 9 Nov, 2007 10:45:38

Message: 3 of 5

PB wrote:
> Den Thu, 08 Nov 2007 14:30:22 +0000 skrev Ben:
>
>> Hi there,
>>
>> I'm trying to perform some operations on a matrix - I have a 20x20
>> matrix that I've got to remove some rows from the top, and re-generate
>> lines at the bottom to leave the matrix the same size as it was.
>>
>> So, say I have a 10x10 matrix, I remove the top row. What I now want to
>> do is generate a row between the row at the bottom, and the one above
>> it, that I can put in to keep it 10x10.
>>
>> I've looked at interp2, and it sort of seems to do what I want, e.g
>> running interp2(Matrix) gives me a 19x19 matrix with an interpolated row
>> between each. Is there any way to point interp2 at a matrix, with row
>> vector 9, and get it to return a 1x10 matrix containing the interpolated
>> row between row vectors 9 and 10, that I can just add to the first
>> matrix?
>>
>> I believe interp2 can sort-of do this, using Xi and Yi, but that appears
>> to be more related to generating an interpolated value from two data
>> points, not two rows?
>>
>> Anyone have any advice?
>>
>> Thanks,
>>
>> Ben
>
> Does this help?
>
> a=magic(3);
> a(:,3)=[] % remove last row
> ix=1:0.5:2;
> [xi,yi]=meshgrid(ix)
> y=interp2(a,xi,yi)
>
>
> /PB

Thanks, but your a= line actually removes the last column and not the
last row...

I changed it to remove the last column, but the final result bears no
resemblance to the original square I'm not sure how the meshgrid of ix
interacts with the interpolation, which is what I think is causing the
wrong results as I changed it from column to row...?

Subject: Interpolation of matrix

From: John D'Errico

Date: 9 Nov, 2007 11:28:08

Message: 4 of 5

Ben <bw.games_n0spam@gmail.nospam.com> wrote in message <mTWYi.
10525$ib1.5678@newsfe3-win.ntli.net>...
> PB wrote:
> > Den Thu, 08 Nov 2007 14:30:22 +0000 skrev Ben:
> >
> >> Hi there,
> >>
> >> I'm trying to perform some operations on a matrix - I have a 20x20
> >> matrix that I've got to remove some rows from the top, and re-
generate
> >> lines at the bottom to leave the matrix the same size as it was.
> >>
> >> So, say I have a 10x10 matrix, I remove the top row. What I now want
to
> >> do is generate a row between the row at the bottom, and the one above
> >> it, that I can put in to keep it 10x10.
> >>
> >> I've looked at interp2, and it sort of seems to do what I want, e.g
> >> running interp2(Matrix) gives me a 19x19 matrix with an interpolated
row
> >> between each. Is there any way to point interp2 at a matrix, with row
> >> vector 9, and get it to return a 1x10 matrix containing the interpolated
> >> row between row vectors 9 and 10, that I can just add to the first
> >> matrix?
> >>
> >> I believe interp2 can sort-of do this, using Xi and Yi, but that appears
> >> to be more related to generating an interpolated value from two data
> >> points, not two rows?
> >>
> >> Anyone have any advice?
> >>
> >> Thanks,
> >>
> >> Ben
> >
> > Does this help?
> >
> > a=magic(3);
> > a(:,3)=[] % remove last row
> > ix=1:0.5:2;
> > [xi,yi]=meshgrid(ix)
> > y=interp2(a,xi,yi)
> >
> >
> > /PB
>
> Thanks, but your a= line actually removes the last column and not the
> last row...
>
> I changed it to remove the last column, but the final result bears no
> resemblance to the original square I'm not sure how the meshgrid of ix
> interacts with the interpolation, which is what I think is causing the
> wrong results as I changed it from column to row...?
>

When you remove information by deleting a row
from a magic square, an interpolant will not know
that the square was a magic one. Also, PB made
a mistake in his example.

a=magic(3);
a(3,:)=[]; % remove last row
ix=1:0.5:2;
iy = 1:3;
[xi,yi]=meshgrid(ix,iy);
y=interp2(a,yi,xi)';


a =
     8 1 6
     3 5 7

y =
            8 1 6
          5.5 3 6.5
            3 5 7

Note the transpose at the end!

HOWEVER. dropping the last row of an array,
then inserting a new one internally to make
up for it by interpolation will not generally
make sense to me. But its your data.

HTH,
John


Subject: Interpolation of matrix

From: Ben

Date: 9 Nov, 2007 16:35:17

Message: 5 of 5

John D'Errico wrote:
> Ben <bw.games_n0spam@gmail.nospam.com> wrote in message <mTWYi.
> 10525$ib1.5678@newsfe3-win.ntli.net>...
>> PB wrote:
>>> Den Thu, 08 Nov 2007 14:30:22 +0000 skrev Ben:
>>>
>>>> Hi there,
>>>>
>>>> I'm trying to perform some operations on a matrix - I have a 20x20
>>>> matrix that I've got to remove some rows from the top, and re-
> generate
>>>> lines at the bottom to leave the matrix the same size as it was.
>>>>
>>>> So, say I have a 10x10 matrix, I remove the top row. What I now want
> to
>>>> do is generate a row between the row at the bottom, and the one above
>>>> it, that I can put in to keep it 10x10.
>>>>
>>>> I've looked at interp2, and it sort of seems to do what I want, e.g
>>>> running interp2(Matrix) gives me a 19x19 matrix with an interpolated
> row
>>>> between each. Is there any way to point interp2 at a matrix, with row
>>>> vector 9, and get it to return a 1x10 matrix containing the interpolated
>>>> row between row vectors 9 and 10, that I can just add to the first
>>>> matrix?
>>>>
>>>> I believe interp2 can sort-of do this, using Xi and Yi, but that appears
>>>> to be more related to generating an interpolated value from two data
>>>> points, not two rows?
>>>>
>>>> Anyone have any advice?
>>>>
>>>> Thanks,
>>>>
>>>> Ben
>>> Does this help?
>>>
>>> a=magic(3);
>>> a(:,3)=[] % remove last row
>>> ix=1:0.5:2;
>>> [xi,yi]=meshgrid(ix)
>>> y=interp2(a,xi,yi)
>>>
>>>
>>> /PB
>> Thanks, but your a= line actually removes the last column and not the
>> last row...
>>
>> I changed it to remove the last column, but the final result bears no
>> resemblance to the original square I'm not sure how the meshgrid of ix
>> interacts with the interpolation, which is what I think is causing the
>> wrong results as I changed it from column to row...?
>>
>
> When you remove information by deleting a row
> from a magic square, an interpolant will not know
> that the square was a magic one. Also, PB made
> a mistake in his example.
>
> a=magic(3);
> a(3,:)=[]; % remove last row
> ix=1:0.5:2;
> iy = 1:3;
> [xi,yi]=meshgrid(ix,iy);
> y=interp2(a,yi,xi)';
>
>
> a =
> 8 1 6
> 3 5 7
>
> y =
> 8 1 6
> 5.5 3 6.5
> 3 5 7
>
> Note the transpose at the end!
>
> HOWEVER. dropping the last row of an array,
> then inserting a new one internally to make
> up for it by interpolation will not generally
> make sense to me. But its your data.
>
> HTH,
> John
>
>


Thanks for the feedback.

I think I was a bit unclear, sorry.

What I want to do, is remove the top row of an array.
Then I want to interpolate at the bottom of the array and create an
interpolated row between the last row, and the row previous to that, to
leave the array the same size as it was before, and the data is roughly
the same.
This has the effect of shifting the previous centre row of the array up
by one, without dramatically affecting my data, which is what I want.


Any ideas?

Thanks,

Ben

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com