Borrar filtros
Borrar filtros

Keep the value of randperm after clear all

3 visualizaciones (últimos 30 días)
Davidra Fantarina ANDRIAMISAINA
Davidra Fantarina ANDRIAMISAINA el 9 de Feb. de 2018
Editada: Stephen23 el 9 de Feb. de 2018
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 comentarios
Pawel Jastrzebski
Pawel Jastrzebski el 9 de Feb. de 2018
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 el 9 de Feb. de 2018
Editada: Stephen23 el 9 de Feb. de 2018
"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:

Iniciar sesión para comentar.

Respuestas (1)

Jos (10584)
Jos (10584) el 9 de Feb. de 2018
  • 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 comentario
Guillaume
Guillaume el 9 de Feb. de 2018
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Workspace Variables and MAT-Files en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by