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

조회 수: 5 (최근 30일)
Brad
Brad 2012년 8월 7일
댓글: Sagar 2014년 3월 7일
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
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
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개)

Brad
Brad 2012년 8월 8일
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 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

Brad
Brad 2012년 8월 8일
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

카테고리

Help CenterFile Exchange에서 Calendar에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by