Clearing functions selectively, excluding ones with persistent vars

조회 수: 4 (최근 30일)
fugue
fugue 2014년 9월 18일
댓글: fugue 2014년 9월 19일
Hi everyone,
I am having memory issues with version 7 (2004) and have to twist and twirl to get around it. I want to clear all the functions at some point, except ones that have persistent variables in them. I create an automatic list for those function names, and find the rest of the function names, but I cannot use the clear command to remove those functions from memory, due to type mismatch. Any ideas on this?
---> clear(setdiff(inmem,pers_fList)) % (pers_fList : function list to keep)
'setdiff' outputs cell array, which 'clear' does not accept. I can't convert it appropriately. Could there be a simple solution to this? Thanks !

채택된 답변

Geoff Hayes
Geoff Hayes 2014년 9월 18일
Stephanie - try creating the cell array as
funcsToClear = setdiff(inmem,pers_fList);
and then clear it with
clear(funcsToClear{:});
I was able to do the above with a similar cell array of strings.
  댓글 수: 1
fugue
fugue 2014년 9월 19일
Thanks Geoff, It worked ! I realize I've known both solutions, but seems like I wasn't able to recall. Thank you both..

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

John Barber
John Barber 2014년 9월 19일
Another approach is to use the mlock function inside of the functions that you want to protect from being cleared. You can then call clear functions without having to worry about keeping a list.
  댓글 수: 1
fugue
fugue 2014년 9월 19일
Thanks a lot John ! This looks like a more pro solution. Below is handier for now :)

댓글을 달려면 로그인하십시오.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by