Out of Memory for using many global variables

1 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2018-2-9
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

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by