- 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 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Vidip Jain
2023년 8월 31일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!