How to Delete Arrays?

조회 수: 58 (최근 30일)
Jay
Jay 2019년 6월 29일
댓글: Steven Lord 2019년 6월 29일
How does one delete arrays (completely) once they have served their specific purpose (saving memory & decluttering the written program)?
I do not want to rename, redimension and then reuse the array (as the coding will inevitably be more difficult to follow and debug).
  댓글 수: 1
Steven Lord
Steven Lord 2019년 6월 29일
If you're writing script files, variables aren't deleted until you explicitly clear them or until the caller's workspace is destroyed. If you're running the scripts from the prompt in the Command Window they're running in the base workspace, which persists until you close MATLAB.
If you're writing function files, the function workspace (and its contents) are destroyed when the function exits after the output arguments have been returned to the caller. [It's a bit more complicated than that with persistent variables, nested functions, etc. but that statement is accurate enough for purposes of this discussion.]
So breaking your program into "bite sized chunks", extracting commonly used steps into functions, can help keep your workspaces organized.

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

채택된 답변

Image Analyst
Image Analyst 2019년 6월 29일
If "myArray" is your array name:
clear('myArray');
  댓글 수: 2
Jay
Jay 2019년 6월 29일
Thank you Image Analyst.
I have to get used to arrays being referred to as variables in coding terminology.
Image Analyst
Image Analyst 2019년 6월 29일
Just to expand on this, it could be any variable -- it doesn't have to be an array. You could get rid of tables, cell arrays, structures, class objects, scalars, or whatever.

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

추가 답변 (1개)

per isakson
per isakson 2019년 6월 29일
편집: per isakson 2019년 6월 29일

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by