필터 지우기
필터 지우기

Keep the value of randperm after clear all

조회 수: 1 (최근 30일)
Davidra Fantarina ANDRIAMISAINA
편집: Stephen23 2018년 2월 9일
I have this code in one script
order = randperm(rows*columns)
And one other script starts with clear all so how can i keep the value of order?
  댓글 수: 4
Pawel Jastrzebski
Pawel Jastrzebski 2018년 2월 9일
Sure thing. I'm still a learner but also believe that when developing a code (especially if you're new to Matlab), first:
  • 'get the code to work'
  • 'get the code to work better'
In other words, efficiency and elegance will come with the experience. Sometimes having a code that simply works (programmed awkwardly, but still works) is better than having no code at all.
Stephen23
Stephen23 2018년 2월 9일
편집: Stephen23 2018년 2월 9일
"And one other script starts with clear all so how can i keep the value of order?"
So don't use clear all. clear all only slows down your code and is very very rarely required anyway, as clear's help states:
"Calling clear all, clear classes, and clear functions decreases code performance, and is usually unnecessary."
Write functions instead of scripts, they avoid all of these trivial problems by having independent workspaces:

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

답변 (1개)

Jos (10584)
Jos (10584) 2018년 2월 9일
  • learn to use functions rather than scripts, pass the variables needed for the second function as arguments. No need for clear all
  • use clearvars rather than clear all
  댓글 수: 1
Guillaume
Guillaume 2018년 2월 9일
Or rather don't use any sort of clear at all.
Any code that I'm given that contains clear all and/or close all, I instantly discard. Don't mess up my workspace, don't close my carefully constructed figures.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by