From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Help with 4D plot
Date: Fri, 9 Jul 2010 05:33:06 +0000 (UTC)
Organization: Macquarie University
Lines: 31
Message-ID: <i16cai$7t$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1278653586 253 (9 Jul 2010 05:33:06 GMT)
NNTP-Posting-Date: Fri, 9 Jul 2010 05:33:06 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2411313
Xref: comp.soft-sys.matlab:651664

I have a 4D dataset of the ocean, comprised of latitude, longitude, depth and time with the variable 'temperature' recorded within these bounds. I want to plot the temperature of a volume of water within 3D space, but can't find the command to do this. 

I understand that I can not plot this for all time in the one graph, so I am selecting a specific time and then using the 'squeeze' command to remove this extra dimension. 

I created a meshgrid for my 'Z' variable since I was not able to just use the 'odepth' vector variable - I kept getting an error stating that Z could not be a vector but needed to be an m-n array. The meshgrid seems to have fixed this problem. 

When I run the code below it falls apart at my 'surf' command, and I get the error message "cdata must be an m-by-n matrix or m-by-n-by-3 array", which I don't understand. 

I can visualise the plot I want: lat and lon on the x and y axis, depth on the z axis, with temperature defining the shading of the plot. Am I using the wrong command?

x=find(olat<=-65.25&olat>=-70.25);  %specify latitude
y=find(lon>=80.4&lon<=179.4);       %specify longitude
%z=find(odepth>=0);                 %depth not specified = all depths
t=find(time==1959);                 %specify time


surf(x,y,zmesh,(squeeze(datanan(x,y,:,t)))) %THIS LINE IS THE PROBLEM
shading flat %adds or removes grid lines
shading interp %smooths the plot to remove the pixels
title ('Temperature - Jan 1959')
xlabel('Latitude (degrees north)')
ylabel('Longitude (degrees east)')

Any help anyone could offer is very much appreciated!