MATLAB: Suppose I have a matrix of size(3,3).This is up-scaled by 2 making it (6,6).So there would be a number of vacant values between each element of the initial (3,3) matrix.Then how do you fill up the 0 values in addmatrixR by bicubic/liner interpolati

matrix manipulation

prevR=magic(3)
m=1;
k1=1
addRmatrix= zeros(2*size(prevR,1),2*size(prevR,2))
for i=1:size(prevR,1);
for j=1:size(prevR,2);
addRmatrix(m,k1)= prevR(i,j);
k1=k1+2 ;
end
m=m+2;
k1=1;
end

Best Answer

Just use interp2:
>> M = magic(3)
M =
8 1 6
3 5 7
4 9 2
>> interp2(M,1)
ans =
8.0000 4.5000 1.0000 3.5000 6.0000
5.5000 4.2500 3.0000 4.7500 6.5000
3.0000 4.0000 5.0000 6.0000 7.0000
3.5000 5.2500 7.0000 5.7500 4.5000
4.0000 6.5000 9.0000 5.5000 2.0000
Or the simplest of all:
>> interp2(M)
ans =
8.0000 4.5000 1.0000 3.5000 6.0000
5.5000 4.2500 3.0000 4.7500 6.5000
3.0000 4.0000 5.0000 6.0000 7.0000
3.5000 5.2500 7.0000 5.7500 4.5000
4.0000 6.5000 9.0000 5.5000 2.0000
If you need to specify the sample points, then do something like this:
>> [Xi,Yi] = meshgrid(1:1.0:S(2),1:1.0:S(1));
>> [Xo,Yo] = meshgrid(1:0.5:S(2),1:0.5:S(1));
>> out = interp2(Xi,Yi, M, Xo,Yo)
out =
8.0000 4.5000 1.0000 3.5000 6.0000
5.5000 4.2500 3.0000 4.7500 6.5000
3.0000 4.0000 5.0000 6.0000 7.0000
3.5000 5.2500 7.0000 5.7500 4.5000
4.0000 6.5000 9.0000 5.5000 2.0000