- 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.
- 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.
- Reduce Unnecessary Calculations: Review your code to ensure that you are only performing calculations that are essential. Eliminate any redundant or unnecessary computations.
- Parallel Computing: If your system supports it, you can take advantage of MATLAB's parallel computing capabilities to distribute computations across multiple cores.
Moving ROI callback "lags" in addlistener function
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
Vidip Jain
el 31 de Ag. de 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:
Refer to this documentation for more information:
0 comentarios
Ver también
Categorías
Más información sobre Graphics Object Programming en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!