필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Beginnning of file considered as code section

조회 수: 2 (최근 30일)
z8080
z8080 2016년 5월 24일
마감: MATLAB Answer Bot 2021년 8월 20일
In my Matlab preferences I only have Sections enabled under Code Folding, so that I can fold cells (code sections). Even so, the beginning of every .m file in the Editor is flagged as the start of a code section, which lasts until the start of the next actual cell:
How can I change this behaviour? Many thanks!
  댓글 수: 2
Stephen23
Stephen23 2016년 5월 24일
편집: Stephen23 2016년 5월 24일
Noticing that there is a problem is the first step to becoming a better programmer. Here are two things you should do:
  1. Stop writing cargo-cult code clear and clc at the start of your scripts.
  2. Learn to write functions instead of scripts.
  3. Read this: http://www.mathworks.com/matlabcentral/answers/228557-experts-of-matlab-how-did-you-learn-any-advice-for-beginner-intermediate-users
z8080
z8080 2016년 5월 24일
Thanks for the advice. That bit of code is actually quite old, I don't really use those commands to start scripts anymore, but in either case, my question is really about how to make code sections start where I want them to, i.e. between %%-lines, rather than having one always start at the beginning of the file.

답변 (1개)

Philip Borghesani
Philip Borghesani 2016년 5월 24일
편집: Philip Borghesani 2016년 5월 24일
My first thought is don't put that code at the top of each script. Especially clear all it slows down the execution of the code because all code must be recompiled after clearing. If you must, use clear without the all to clear variables from the base workspace.
My second thought is to write functions instead of scripts or to give up and create a section marker at the top of the file:
Blast the base workspace to remove all previous work without prompting to save
clc
clear

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by