Matlab not converting from single to double (but it thinks it is...)
5 ビュー (過去 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!