Out of Memory for using many global variables

2 vues (au cours des 30 derniers jours)
roudan
roudan le 9 Fév 2018
Commenté : Walter Roberson le 9 Fév 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 commentaires
Greg
Greg le 9 Fév 2018
doc guidata
Walter Roberson
Walter Roberson le 9 Fév 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

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by