Reputation: 2263
I have data on 25 points like this:
Z=
0.6840 0.7208 1.0240 1.0293 0.7713
0.8602 0.9089 1.3414 0.8970 0.7107
0.8869 0.8282 1.7015 0.9967 0.9243
0.7469 0.9534 1.5206 1.2741 1.0281
0.8952 1.1554 0.8525 1.2993 0.9890
pcolor(Z)=
Pcolor interpolates the data to form the colours but doesn't give me the value of each new square. I'd like to do this manually via interpolation
:
I'd like to average these pink points to make an interpolated value at the centre of each square ie the blue numbers.
This doesn't seem to do that.
x=1:5;
y=1:5;
xi=0.5:1:5;
yi=0.5:1:5;
ZI=interp2(x,y,Z,xi,yi);
gives: ZI =
0.8918 1.0778 0.8194 NaN NaN
0.9084 1.3375 0.8967 NaN NaN
1.0035 1.5858 0.8852 NaN NaN
1.1633 1.4250 1.0040 NaN NaN
NaN NaN NaN NaN NaN
Any pointers would be appreciated, Regards,
Upvotes: 0
Views: 1119
Reputation: 75896
It's not clear if you want an supersampled matrix or just the interpolated values. If the later, you could simply do:
Z = [ 0.6840 , 0.7208 , 1.0240 , 1.0293 , 0.7713;
0.8602 , 0.9089 , 1.3414 , 0.8970 , 0.7107;
0.8869 , 0.8282 , 1.7015 , 0.9967 , 0.9243;
0.7469 , 0.9534 , 1.5206 , 1.2741 , 1.0281;
0.8952 , 1.1554 , 0.8525 , 1.2993 , 0.9890];
Z1 = (Z(1:end-1,1:end-1)+Z(2:end,1:end-1)+Z(1:end-1,2:end)+Z(2:end,2:end))/4
ans =
0.79348 0.99877 1.07293 0.85208
0.87105 1.19500 1.23415 0.88218
0.85385 1.25093 1.37322 1.05580
0.93773 1.12047 1.23662 1.14762
Or if you really want to use the interp2
function: (I use a 5x4 matrix so that it's more instructive)
Z = [ 0.6840 , 0.7208 , 1.0240 , 1.0293 , 0.7713;
0.8602 , 0.9089 , 1.3414 , 0.8970 , 0.7107;
0.8869 , 0.8282 , 1.7015 , 0.9967 , 0.9243;
0.7469 , 0.9534 , 1.5206 , 1.2741 , 1.0281]
interp2(Z,[1:4 ]+0.5,[1:3]'+0.5)
0.79348 0.99877 1.07293 0.85208
0.87105 1.19500 1.23415 0.88217
0.85385 1.25093 1.37322 1.05580
(tested in Octave)
Upvotes: 2