Matlab not converting from single to double (but it thinks it is...)
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
the cyclist
2012-8-8
I get a dimension mismatch error on line 57 of pcolor when I try to run this code.
采纳的回答
the cyclist
2012-8-8
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))
更多回答(3 个)
per isakson
2012-8-8
编辑:per isakson
2012-8-8
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calendar 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!