MATLAB: How to extract specific data from one dimension of a 3D variable

3dinterpolationpressurewrf

I am looking at a WRF output data file. I am attempting to look at the winds across a constant level of pressure. My 3D pressure variable is of the form P(lat, lon, z), where z has 39 levels. For all latitudes and longitudes I want to know where Z is at a value around 700 hPa. I am new to Matlab and cannot figure out how to do this. I would appreciate any suggestions.
Thanks.

Best Answer

Not quite sure I follow -- 'z' is an elevation, not a pressure, correct? And all values in P are pressures?
But, presuming is so use find or logical addressing--
idx=find(iswithin(P,Plo,Phi));
where the helper function iswithin is a little utility I have that looks like
function flg=iswithin(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
flg= (x>=lo) & (x<=hi);
So, for your case it might be something like
Ptgt=700; dP = 10;
iP700=find(iswithin(P,Ptgt,Ptgt-dp,Ptgt+dp));
iP700 will be a linear index into the array for those values matching the condition that you can use to address other arrays of the same dimension.
Or, you can simply return a logical array of the same size as P and use that as the addressing expression...
lP700=iswithin(P,Ptgt,Ptgt-dp,Ptgt+dp;