1
$\begingroup$

I am trying to construct a complicated code in which I need to name a lot of variables and their definitions.

For Example:

enter image description here

The problem is as follow:

Once I insert new variable in between two, I have to re-number the subscripts number in the SS & ss. Is there a way to make this automatic numbering?

Keeping in mind that if I re-execute the same part of code the numbering must be the same.

$\endgroup$
4
$\begingroup$

Subscripts are evil. Why don't you use an Association? This would get you rid of the whole numbering business. This could look like this:

value = Association[
   "grav" -> 9.81,
   "L" -> 100 10^6
   ];
help = Association[
   "grav" -> "gravitational acc",
   "L" -> "Length"
   ];

You need the value of "L"? Call value["L"]. You need help on "grav"? Call help["grav"]. You want to know which variable names you have? Execute Keys[value].

$\endgroup$
  • $\begingroup$ The problem is, as the code get complicated the variables name get closer to each other. So, by calling ss_1 it will give the gravity with out the need of memorizing the actual variable spelling. $\endgroup$ – Love Eva Apr 15 '18 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.