how can I use matlab interpolation?

Hi every body,
I have a matrix (N*M) and I want increase the column with interpolation. the first size N=100 M=50 and new size N=100 M=200 how can I use interpolation for matrix?

Answers (2)

k = rand(100,1) ; % increase to 200
x1 = 1:2:200 ; % make arbitrary indices/ x values
y1 = k ;
% inteprolation
xi = 1:200 ;
yi = interp1(x1,y1,xi) ;

1 Comment

Note that this answer throws an error when the input is a matrix (which the question clearly requires):
>> mat = randi(9,4,5)
mat =
6 7 6 3 7
1 7 2 1 3
8 7 7 1 9
9 4 1 8 1
>> xi = 1:2:10;
>> yi = mat;
>> xo = 1:10;
>> interp1(xi,yi,xo)
Error using griddedInterpolant
The grid vectors do not define a grid of points that match the given values.
Error in interp1>Interp1D (line 346)
F = griddedInterpolant(Xext,V,method);
Error in interp1 (line 241)
Vq = Interp1D(X,V,Xq,method);
Also note that when called using the author's own example it attempts to extrapolate outside the original matrix:
>> k = rand(100,1);
>> x1 = 1:2:200;
>> y1 = k;
>> xi = 1:200;
>> yi = interp1(x1,y1,xi)
yi =
Columns 1 through 13
0.4898 0.4677 0.4456 0.5459 0.6463 0.6778 0.7094 0.7320 0.7547 0.5154 0.2760 0.4779 0.6797
... more here
Columns 196 through 200
0.4321 0.5132 0.4575 0.4018 NaN
The NaN at the end indicates that this code has tried to extrapolate the data.
See my answer for code that works correctly on matrices, as the question requires.
Stephen23
Stephen23 on 20 Jun 2016
Edited: Stephen23 on 6 Jul 2016
>> inp = randi(9,4,5)
inp =
8 4 3 6 4
2 1 1 4 2
8 8 5 2 3
6 1 3 1 3
>> xi = 1:2:2*size(inp,2);
>> xo = 1:xi(end);
>> out = interp1(xi,inp.',xo).'
out =
8 6 4 3.5 3 4.5 6 5 4
2 1.5 1 1 1 2.5 4 3 2
8 8 8 6.5 5 3.5 2 2.5 3
6 3.5 1 2 3 2 1 2 3

This question is closed.

Asked:

on 20 Jun 2016

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!