Filter löschen
Filter löschen

Moving ROI callback "lags" in addlistener function

7 Ansichten (letzte 30 Tage)
Nikan Fakhari
Nikan Fakhari am 16 Jun. 2022
Beantwortet: Vidip Jain am 31 Aug. 2023
Hi there,
I have created a callback function using addlistener to excetue whenever I move my ROI object in a figure. This was done
in may matlab class:
addlistener(obj.ROI,'MovingROI',@(src,evnt)obj.myfunction(src,evnt))
However in my call back function "myfunction" I need to do a 3D by 2D matrix multplication every time i move the object,
and I can see in the figure that there is always "lag" as soon as I move the object.
I assume that this is becasue my call back function is super slow to perform this multiplication.
I would appreciate it if someone can help me to bypass this issue
Best,
Nikan

Antworten (1)

Vidip Jain
Vidip Jain am 31 Aug. 2023
I understand that your call back function is super slow to perform a 3D by 2D matrix multiplication due to which there is always "lag" as soon as the object is moved.
You can consider optimizing the code within your callback to improve performance. Here are some strategies to consider:
  1. Vectorization: Use vectorized operations whenever possible. MATLAB is highly optimized for vectorized computations. Instead of looping through elements, operate on entire arrays/matrices at once.
  2. Preallocate Arrays: If your callback frequently creates new arrays or matrices, consider preallocating them outside the callback to avoid unnecessary memory reallocation during each callback invocation.
  3. Reduce Unnecessary Calculations: Review your code to ensure that you are only performing calculations that are essential. Eliminate any redundant or unnecessary computations.
  4. Parallel Computing: If your system supports it, you can take advantage of MATLAB's parallel computing capabilities to distribute computations across multiple cores.
Refer to this documentation for more information:

Community Treasure Hunt

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

Start Hunting!

Translated by