Is it possible to organize variables shown in workspace?

31 views (last 30 days)
Zeynab Mousavikhamene
Zeynab Mousavikhamene on 5 Sep 2019
Edited: Stephen on 5 Sep 2019
I am interested to arrange parameters shown in the workspace based on the script. I have two scripts now and one script calls the other one. At the end of simulation variables of two scripts are shown in workspace alphabetically. Is it possible to sort them by script so that the variables of script one are shown first and then the variables of script two?

Answers (1)

Stephen
Stephen on 5 Sep 2019
Edited: Stephen on 5 Sep 2019
"At the end of simulation are variables of two scripts are shown in workspace alphabetically. Is it possible to sort them by script?"
No.
It doesn't even make sense, because variables in a workspace do not have an "order". How they are displayed is simply an artefact of the displaying functionality of the MATLAB IDE, which is not specified to be in any particular "order", it could also change between different MATLAB versions.
In contrast (and by definition) all arrays do have an order: the 1st array element comes 1st, the 2nd array element comes 2nd, etc.
If you want to sort data into a specific order, you need to use an array (which could be a numeric array, a cell array, a structure array, a table, etc.).
Note that putting meta-data into variable names (which most likely you have) is not recommended. Accessing meta-data in variable names is one way that beginners force themselves into writing slow, complex, obfuscated, buggy code that is hard to debug. Read this to know why:

Community Treasure Hunt

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

Start Hunting!