How to pass big Matrices to function fastly?
이전 댓글 표시
Hi,
I have a function which is called many times over and over in a simulation. The function calculates and changes values of a matrix (70^3 elements) and the matrix then is plotted. Due to more readability, I moved a big chunk of the code to a new function. I also pass the big matrix to the function and then get the changed matrix back. Is there a way to do this more efficiently than just passing the variable that contains the matrix? Like in other languages just passing the address or something... Because the simulation became much slower after I've made the changes.
Thanks!
댓글 수: 2
Walter Roberson
2020년 6월 7일
Double check that you preallocated your arrays where appropriate.
채택된 답변
추가 답변 (1개)
Image Analyst
2020년 6월 6일
0 개 추천
How big is the "big" matrix. Surely you don't mean the one with 70^3 elements.
>> 70^3
ans =
343000
That's only like one percent the size of a typical digital image these days, and should be no problem. So for the other, BIG matrix, are we talking hundreds of megabytes, or gigabytes? And have you looked into memmapfile()?
댓글 수: 2
BananaBandana
2020년 6월 7일
Image Analyst
2020년 6월 7일
There could be many reasons. For example one common one with images is if people call hold on and then repeatedly load images with imshow(). All those prior images in the axes will stay there and the new one just gets put on top of them so the memory used grows and grows and the program gets slower and slower. Try calling hold off and cla reset right before you call imshow. Try calling memory at key points in your program to see where the memory gets used up.
카테고리
도움말 센터 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!