How to pass big Matrices to function fastly?
Mostrar comentarios más antiguos
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 comentarios
Walter Roberson
el 7 de Jun. de 2020
Double check that you preallocated your arrays where appropriate.
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 6 de Jun. de 2020
0 votos
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 comentarios
BananaBandana
el 7 de Jun. de 2020
Image Analyst
el 7 de Jun. de 2020
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.
Categorías
Más información sobre Resizing and Reshaping Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!