Loop function takes too long. How can I reduce the processing time?

조회 수: 1 (최근 30일)
Ibrahim Suleiman
Ibrahim Suleiman 2021년 5월 19일
댓글: Ibrahim Suleiman 2021년 5월 23일
Hi,
I have got a signal obtained from experimental data. It is a force-time series graph that I am looking at here. I want to find the derivative of every single point on the signal. This is to identify the ramps of the signal peaks and then to find the rate of force development. I also want to plot the differentials as tangents on signal to visualise it.
I have constructed a loop to find the derivatives.
Here is the loop.
% Find the derivative of all points on the signal
for idx = 2:length(s)
diff = s(idx) - s(idx-1);
figure;
plot(x,s)
hold on
plot(diff)
hold off
end
It takes more than half an hour. I dont know how long it exactly takes because stop the processing at every attempt to run it.
The variable s is a collumn vector with size 79693, so I do understand that this could be the reason why it is so slow. Is there any way to increase the speed of running this part of code?
I have attached my file.
  댓글 수: 1
Jan
Jan 2021년 5월 19일
Currently you open 79000 figures. How could this be useful? It would take days to check them with your eyes. Opening 40 figures at the same time might be an upper limit of what is useful.

댓글을 달려면 로그인하십시오.

답변 (1개)

Stephan
Stephan 2021년 5월 19일
편집: Stephan 2021년 5월 19일
Yes, diff in as inbuilt and vectrorized function to get what you want. Run this command on a vector input will give you all the results in a very short time. Then plot all the results you get at once. The loop is not needed:
ds = diff(s)
plot(x,ds)
  댓글 수: 1
Ibrahim Suleiman
Ibrahim Suleiman 2021년 5월 23일
Thank you for your answer. I now have the derivatives of the entire signal. But I need to know the rate at which the signal moves from the baseline to the peaks. Any idea how I can achieve that?
I was hoping I could index the range of x values where the signal goes from the baseline to the peaks and calculate/select those derivatives only but that does not seem possible with diff.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by