Quantcast
Channel: MATLAB Central Newsreader - tag:"find"
Viewing all articles
Browse latest Browse all 55

Re: 'Find' in a for loop (beginner question)

$
0
0
"followingseas" wrote in message <mvpja7$pp4$1@newscl01ah.mathworks.com>...
> Hello,
>
> I'm trying to get produce a vector for a mixed layer depth using seawater density information. My sigma variable is a function of salinity and temperature (both 12x24 matrices - 12 months, 24 depths.) I'm trying to determine a mixed layer depth for each month by finding the depth at which the value of density (sigma) is greater than the surface depth + a criterion. I'm quite new to MatLab, and can't figure out why my result is as follows:
>
> 0 0 0 0 0 0 0 0 0 0 0 7
>
> Just eyeballing my sigma values, the last value (December) appears to be reasonable. No idea why I'm getting zeros for the rest of the values. As I mentioned, I've only started using MatLab two weeks ago, so it may be a simple answer.
>
> Here's the relevant part of my code:
>
> sigma=sw_dens0(datsal,dattemp) %size 12x24
> crit=0.05;
>
> for i=numel(temperature.time)
> index(i)=find(sigma(i,:)>(sigma(i,1)+crit),1,'first')
> end
>
> Thanks

Is it possible that that is indeed the correct answer? That is, sigma(I,1) is the largest value for all the prior cases. To check, output sigma(I,:) each time thru the loop or learn how to use the debugger by setting breakpoints.

Viewing all articles
Browse latest Browse all 55

Trending Articles