output of interp2 is single - why?

when I use the following code, the output zcovis is a single rather than a double.
if true
surf(xb,yb,zb)
[xcovis,ycovis]=ginput(1);
zcovis = interp2(xb,yb,zb,xcovis,ycovis);
end
xb,yb,zb are imported data but xb,yb should be consistent with meshgrid format (zb is height above surface not a third coordinate)
why is zcovis a single? I'd like to use it to place a text comment on a another figure:
if true
text(0.1,zcovis+4.2,'COVIS')
end

2 Kommentare

KSSV
KSSV am 9 Aug. 2018
Check the classes of xb,yb and zb..they could be single.
Walter Roberson
Walter Roberson am 9 Aug. 2018
What are class(xb), class(yb), class(zb) ?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

ANKUR KUMAR
ANKUR KUMAR am 9 Aug. 2018

1 Stimme

It's because of your xb,yb,zb, xcovis and ycovis are single. If you want your output in double, just use double before using interp2.
zcovis = double( interp2(xb,yb,zb,xcovis,ycovis));

3 Kommentare

thanks, this and the previous comment clarify what I hadn't noticed before:
while xb and yb are doubles, zb is actually single.
zcovis = interp2(xb, yb, double(zb), xcovis, ycovis);
ANKUR KUMAR
ANKUR KUMAR am 10 Aug. 2018
Bearbeitet: Stephen23 am 10 Aug. 2018
Make all inputs having the same class. This works well, as suggested by Walter Roberson.

Melden Sie sich an, um zu kommentieren.

Produkte

Version

R2015b

Gefragt:

am 9 Aug. 2018

Bearbeitet:

am 10 Aug. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by