Using fnval in for loop SLOW
Using fnval in for loop SLOW
(OP)
Hello all,
I am writing a code for some data analysis, and I have to fit a spline to the local max and min points in data. To fit the spline I am using
fun1 = csape(x1,y1)
fun2 = csape(x2,y2)
I then have to find the mean of the two splines. For that I use the following code. (I did not want to use a for loop! I know this is not efficient coding in MATLab.)
for j=1:n
m(j) = (funval(time(j),fun1) + funval(time(j),fun2))/2;
end
I originally tried this
m(1:n) = (funval(time(1:n),fun1) + funval(time(1:n),fun2))/2
MATLab did not like this. Is there anyway to do this without running a for loop. In some cases n > 20000, and I will have to repeat this 1000 times per case. And I might have 15 cases, and I don't want to have to wait two days for my results. So I guess I am asking is there a way to do this without using a for loop, or is there a way that I can get my sline to be defined by an array and not a function? Any ideas would be greatly appreciated. The fnval takes a while on its own, put it in a for loop and it takes forever.
Regards,
jason m.
I am writing a code for some data analysis, and I have to fit a spline to the local max and min points in data. To fit the spline I am using
fun1 = csape(x1,y1)
fun2 = csape(x2,y2)
I then have to find the mean of the two splines. For that I use the following code. (I did not want to use a for loop! I know this is not efficient coding in MATLab.)
for j=1:n
m(j) = (funval(time(j),fun1) + funval(time(j),fun2))/2;
end
I originally tried this
m(1:n) = (funval(time(1:n),fun1) + funval(time(1:n),fun2))/2
MATLab did not like this. Is there anyway to do this without running a for loop. In some cases n > 20000, and I will have to repeat this 1000 times per case. And I might have 15 cases, and I don't want to have to wait two days for my results. So I guess I am asking is there a way to do this without using a for loop, or is there a way that I can get my sline to be defined by an array and not a function? Any ideas would be greatly appreciated. The fnval takes a while on its own, put it in a for loop and it takes forever.
Regards,
jason m.
"Education is what remains after one has forgotten everything he learned in school." Albert Einstein





RE: Using fnval in for loop SLOW
ie..
m(1:n) = fnval(t(1:n),f1) + fnval(t(1:n),f2)
not sure what I was doing wrong before, but this does work, and my time to compute on cycle went from 2.4sec to .35sec.
Regards,
jason m.
"Education is what remains after one has forgotten everything he learned in school." Albert Einstein