Matlab not converting from single to double (but it thinks it is...)
4 views (last 30 days)
Show older comments
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
1 Comment
the cyclist
on 8 Aug 2012
I get a dimension mismatch error on line 57 of pcolor when I try to run this code.
Accepted Answer
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)
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
0 Comments
See Also
Categories
Find more on Title 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!