How can I find out exact time of simulation?

1 view (last 30 days)
Hi everybody,
I made a GUI that shows some visual stimuli to a subject. Subject must click on the screen at the time he/she watches the target stimuli. I used tic toc function to find out the exact time of clicks. But I found out that a bias is apeard in results gradually. For example, at first reaction time is about 300 or 400 ms but after some clicking this reaction time turns to 700 or 800 ms. What can I do to fix this problem ? Is there another function instead of tic toc to extract exact time of simulation from the begining?
  1 Comment
Walter Roberson
Walter Roberson on 26 Sep 2015
Is the question what the current simulated time is? Or is the question how long you some particular function is requiring to execute in actual clock time?

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 26 Sep 2015
If you are adding data to the end of arrays, that operation gets slower as the array size increases. When the final size of an array is known it is best to pre-allocate the entire array.
In cases where you do not know ahead of time how long an array is going to be, you can improve efficiency by allocating it in chunks, and then when you get to the end of a chunk, allocating another complete chunk. For example you might not know whether you are going to have 2000 or 20000 lines of input, but you can allocate in chunks of 5000; when you need the 5001'st entry extend the array all the way to 10000, keep going on that until reach the end of that, allocate more, and so on. At the end once you know how much you really needed you can discard the extra unused space in the array fairly efficiently. Extending one entry at a time really adds up in time.
  2 Comments
sepehr mortaheb
sepehr mortaheb on 26 Sep 2015
Hi Walter I used preallocation technique but it didn't work and bias still exists!!!
Walter Roberson
Walter Roberson on 26 Sep 2015
Is the question what the current simulated time is? Or is the question how long you some particular function is requiring to execute in actual clock time?

Sign in to comment.

Categories

Find more on App Building in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!