From: Chris on
Hi,

I have two excel data sets of 12013 numbers each. One is maximum sediment diameter, and the second is mean sediment diameter. I have code that calculates the critical shear stress. I am trying to do this for each of the 12013 samples. What I have done so far is use xlsread to import the data into matlab, max and mean are the two names. I trying to use the code with a for loop to calculate the critical shear stress:

rho_s = 2650;
beta = 0;
temp = 10;
sal = 25;

for j = 1:12013
stress(j,1) = CriticalShearStress(max(j,1), rho_s, mean(j,1), beta, temp, sal);
end
I ended up letting this sit over night and came back and it still was incomplete and said busy. I did a little investication and found out that it works fine as long as the for loop is only 220 repetitions. This causes a problem because I would have to break the files up into 55 segements of 220... way to much tedious work. Could some one please suggest or help me troubleshoot this.

Thanks
From: Walter Roberson on
Chris wrote:

> for j = 1:12013
> stress(j,1) = CriticalShearStress(max(j,1), rho_s, mean(j,1), beta,
> temp, sal);
> end

Did you call your variables "max" and "mean" ?? Using a variable name
that is the same as a matlab function is an invitation for problems!

> I did a little investication and found out that it works fine as long
> as the for loop is only 220 repetitions.

Sounds like a job for the Matlab profiler.

For example you do not show any initialization of "stress" so you appear
to be growing "stress" in a loop. That kind of thing can kill performance.

Note: if you have a column vector, then X(J,1) can be written as X(J)
From: James Tursa on
"Chris " <chris.veinot(a)hotmail.com> wrote in message <hv8adq$obf$1(a)fred.mathworks.com>...
> Hi,
>
> I have two excel data sets of 12013 numbers each. One is maximum sediment diameter, and the second is mean sediment diameter. I have code that calculates the critical shear stress. I am trying to do this for each of the 12013 samples. What I have done so far is use xlsread to import the data into matlab, max and mean are the two names. I trying to use the code with a for loop to calculate the critical shear stress:
>
> rho_s = 2650;
> beta = 0;
> temp = 10;
> sal = 25;

Preallocate your result, don't increase its size incrementally in a loop since that causes the entire data set to be copied each time. So insert this line here:

stress = zeros(12013,1);

> for j = 1:12013
> stress(j,1) = CriticalShearStress(max(j,1), rho_s, mean(j,1), beta, temp, sal);
> end
> I ended up letting this sit over night and came back and it still was incomplete and said busy. I did a little investication and found out that it works fine as long as the for loop is only 220 repetitions. This causes a problem because I would have to break the files up into 55 segements of 220... way to much tedious work. Could some one please suggest or help me troubleshoot this.

Also, it is poor programming practice to name your variables the same as intrinsic MATLAB functions. "max" and "mean" and "beta" and "j" are all poor variable name choices.

James Tursa
From: Chris on
"James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <hv8bgs$5g2$1(a)fred.mathworks.com>...
> "Chris " <chris.veinot(a)hotmail.com> wrote in message <hv8adq$obf$1(a)fred.mathworks.com>...
> > Hi,
> >
> > I have two excel data sets of 12013 numbers each. One is maximum sediment diameter, and the second is mean sediment diameter. I have code that calculates the critical shear stress. I am trying to do this for each of the 12013 samples. What I have done so far is use xlsread to import the data into matlab, max and mean are the two names. I trying to use the code with a for loop to calculate the critical shear stress:
> >
> > rho_s = 2650;
> > beta = 0;
> > temp = 10;
> > sal = 25;
>
> Preallocate your result, don't increase its size incrementally in a loop since that causes the entire data set to be copied each time. So insert this line here:
>
> stress = zeros(12013,1);
>
> > for j = 1:12013
> > stress(j,1) = CriticalShearStress(max(j,1), rho_s, mean(j,1), beta, temp, sal);
> > end
> > I ended up letting this sit over night and came back and it still was incomplete and said busy. I did a little investication and found out that it works fine as long as the for loop is only 220 repetitions. This causes a problem because I would have to break the files up into 55 segements of 220... way to much tedious work. Could some one please suggest or help me troubleshoot this.
>
> Also, it is poor programming practice to name your variables the same as intrinsic MATLAB functions. "max" and "mean" and "beta" and "j" are all poor variable name choices.
>
> James Tursa

I thought this was going to work, but unfortunatly it is still stalling at busy
From: Chris on
"Chris " <chris.veinot(a)hotmail.com> wrote in message <hv8gg4$po3$1(a)fred.mathworks.com>...
> "James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <hv8bgs$5g2$1(a)fred.mathworks.com>...
> > "Chris " <chris.veinot(a)hotmail.com> wrote in message <hv8adq$obf$1(a)fred.mathworks.com>...
> > > Hi,
> > >
> > > I have two excel data sets of 12013 numbers each. One is maximum sediment diameter, and the second is mean sediment diameter. I have code that calculates the critical shear stress. I am trying to do this for each of the 12013 samples. What I have done so far is use xlsread to import the data into matlab, max and mean are the two names. I trying to use the code with a for loop to calculate the critical shear stress:
> > >
> > > rho_s = 2650;
> > > beta = 0;
> > > temp = 10;
> > > sal = 25;
> >
> > Preallocate your result, don't increase its size incrementally in a loop since that causes the entire data set to be copied each time. So insert this line here:
> >
> > stress = zeros(12013,1);
> >
> > > for j = 1:12013
> > > stress(j,1) = CriticalShearStress(max(j,1), rho_s, mean(j,1), beta, temp, sal);
> > > end
> > > I ended up letting this sit over night and came back and it still was incomplete and said busy. I did a little investication and found out that it works fine as long as the for loop is only 220 repetitions. This causes a problem because I would have to break the files up into 55 segements of 220... way to much tedious work. Could some one please suggest or help me troubleshoot this.
> >
> > Also, it is poor programming practice to name your variables the same as intrinsic MATLAB functions. "max" and "mean" and "beta" and "j" are all poor variable name choices.
> >
> > James Tursa
>
> I thought this was going to work, but unfortunatly it is still stalling at busy

Solved! thanks for the help
 |  Next  |  Last
Pages: 1 2
Prev: sigTOOL
Next: faster way to add certain elements ?