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 interpolation

1 次查看(过去 30 天)
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

采纳的回答

Stephen23
Stephen23 2017-7-17
编辑:Stephen23 2017-7-17
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
  4 个评论
Stephen23
Stephen23 2017-7-17
编辑:Stephen23 2017-7-17
@MSP: Xi and Yi are sample locations of the input data values: I defined these arbitrarily to be with steps of one. Xo and Yo are the sample locations of the output data values: I defined these to have half the step size of the input steps (steps of 0.5).

请先登录,再进行评论。

更多回答(1 个)

C.J. Harris
C.J. Harris 2017-7-17
Just use interp2 on the original matrix, like so:
prevR = magic(3)
ans =
8 1 6
3 5 7
4 9 2
addRmatrix = interp2(prevR,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

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by