Out of Memory for using many global variables

8 visualizaciones (últimos 30 días)
roudan
roudan el 9 de Feb. de 2018
Comentada: Walter Roberson el 9 de Feb. de 2018
Hi
I have many functions. so instead of use the variables as function arguments to transfer values between functions. I set many variables as global variables. These global variables are not used all the time.
on the top of main function, I did use the following to clear the space.
clc clear all; close all; however, when opening a big excel file(200MB), I ran into out of memory issue for 2014b version. When I change it to use 2017 version. the issue was gone but loading speed for opening excel using xlread() is still very slow. Now I need your help on the following questions.
1. How to reduce memory space with many global variables? How to only assign space when it is used? 2. I have few toolboxes, like statistics, which are only linked to 2014b version. Is it possible to use these toolbox for 2017 version?
Thank you so much for your help. I appreciate it.
  11 comentarios
Greg
Greg el 9 de Feb. de 2018
Walter Roberson
Walter Roberson el 9 de Feb. de 2018
If you have enough data to be running out of memory, you should be using setappdata()/getappdata() instead of guidata(). guidata() is invoked by GUIDE for every callback, and a copy of all the stored data is created each time. With setappdata()/getappdata(), you can pull in copies of just the data you need.
Even then, since the data is large, you should probably instead rewrite your code to use nested functions with shared variables -- or create a handle object containing the array, possibly using https://www.mathworks.com/help/matlab/matlab_oop/handle-compatible-classes-and-heterogeneous-arrays.html

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps 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!

Translated by