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 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Stephen23
on 17 Jul 2017
Edited: Stephen23
on 17 Jul 2017
>> 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 Comments
Stephen23
on 17 Jul 2017
Edited: Stephen23
on 17 Jul 2017
@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).
More Answers (1)
C.J. Harris
on 17 Jul 2017
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
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!