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
0 个评论
采纳的回答
Stephen23
2017-7-17
编辑:Stephen23
2017-7-17
>> 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 个评论
更多回答(1 个)
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 Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!