Matlab not converting from single to double (but it thinks it is...)

3 views (last 30 days)
I am trying to use the pcolor function to plot ocean data from a climate database. I download the data using the following code that is part of a function I wrote:
var_lat = ncread('http://iridl.ldeo.columbia.edu/expert/SOURCES/.NOAA/.NODC/.WOA09/.Grid-1x1/.Annual/.salinity/.s_an/dods','lat');
var_lon = ncread('http://iridl.ldeo.columbia.edu/expert/SOURCES/.NOAA/.NODC/.WOA09/.Grid-1x1/.Annual/.salinity/.s_an/dods','lon');
var_time = ncread('http://iridl.ldeo.columbia.edu/expert/SOURCES/.NOAA/.NODC/.WOA09/.Grid-1x1/.Annual/.salinity/.s_an/dods','time');
var_depth = ncread('http://iridl.ldeo.columbia.edu/expert/SOURCES/.NOAA/.NODC/.WOA09/.Grid-1x1/.Annual/.salinity/.s_an/dods','depth');
var_s_an = ncread('http://iridl.ldeo.columbia.edu/expert/SOURCES/.NOAA/.NODC/.WOA09/.Grid-1x1/.Annual/.salinity/.s_an/dods','s_an');
s_an=struct('lat', var_lat, 'lon', var_lon, 'time', var_time, 'depth', var_depth, 's_an', var_s_an);
Sal=struct('s_an', s_an);
(This used to be much easier before release 12:
%addpath('C:\Program Files\MATLAB\R2008b\opendap\loaddap')
%Sal=loaddap('http://iridl.ldeo.columbia.edu/expert/SOURCES/.NOAA/.NODC/.WOA09/.Grid-1x1/.Annual/.salinity/.s_an/dods');)
The goal is to plot pcolor(Sal.s_an.lat, Sal.s_an.lon, Sal.s_an.s_an) for a subset of the data defined in the function inputs. I get the following error:
Warning: CData must be double or uint8.
Warning: CData must be double or uint8.
Warning: CData must be double or uint8.
Warning: CData must be double or uint8.
Warning: CData must be double or uint8.
Warning: CData must be double or uint8.
Warning: CData must be double or uint8.
Warning: CData must be double or uint8.
It always comes up 8 times.
Here is the kicker. If I manually extract the Lat, Lon, and s_an variable sets, and use the 'double' function to make them doubles, I still get the same errors using the pcolor function.
Why will Matlab continue to see these sets of numbers as single precision? What's going on behind the scenes here?
Thank you,
Brad

Accepted Answer

the cyclist
the cyclist on 8 Aug 2012
If I run this code:
[xx,yy] = meshgrid(Sal.s_an.lat,Sal.s_an.lon);
zz = Sal.s_an.s_an(:,:,1);
pcolor(xx,yy,zz)
then I get your warnings. xx,yy, and zz are type single. If I change the last line to this, I do not get the warning:
pcolor(double(xx),double(yy),double(zz))

More Answers (3)

Brad
Brad on 8 Aug 2012
Thanks cyclist. I've tried that very solution already, and it didn't work here! That is the reason that I went to the forum - I can verify that I am trying to plot 3 double precision data sets, and Matlab tells me otherwise!
Maybe I just need a reboot...
What version are you using? I'm using 12a.
Brad

per isakson
per isakson on 8 Aug 2012
Edited: per isakson on 8 Aug 2012
It works for me with R2012a 64bit on Windows7 - no warnings
...
zz( zz > 1e36 ) = nan;
pcolor(double(xx),double(yy),double(zz))
The value 9.9692100e+36 is frequent in the data

Brad
Brad on 8 Aug 2012
A reboot of Matlab seemed to get it working again. Thank you for all the help - cyclist and per isakson. Per isakson, I replace the high values with NaN like you have (although I use a clumsy for loop with an if loop nested inside, your code is much simpler).
Brad

Community Treasure Hunt

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

Start Hunting!