(Created page with "= Mathematica tips and tricks = This is a list of Mathematica tips and tricks. == Progress bar == Use before any (long) loop over $i$: <pre> ProgressIndicator[Dynamic[i],...") |
|||
Line 2: | Line 2: | ||
This is a list of [[Mathematica]] tips and tricks. | This is a list of [[Mathematica]] tips and tricks. | ||
+ | |||
+ | == Position == | ||
+ | |||
+ | Often you want something like this: | ||
+ | |||
+ | <pre> | ||
+ | Position[mylist,#!=0&] | ||
+ | </pre> | ||
+ | |||
+ | which is not syntactically correct in Mathematica (this syntax works in Select[] for instance, but not in Cases[], to me it's a bit inconsistent). | ||
+ | |||
+ | The following almost works: | ||
+ | |||
+ | <pre> | ||
+ | Position[mylist,Expect[0]] | ||
+ | </pre> | ||
+ | |||
+ | but it finds the head of your list and apparently other things as well, so you get results like {0}. | ||
+ | |||
+ | It's better to process ''mylist'' directly: | ||
+ | |||
+ | <pre> | ||
+ | Position[#!=0&/@mylist,True] | ||
+ | </pre> | ||
== Progress bar == | == Progress bar == | ||
Line 10: | Line 34: | ||
ProgressIndicator[Dynamic[i], {imin, imax}] | ProgressIndicator[Dynamic[i], {imin, imax}] | ||
</pre> | </pre> | ||
+ | |||
+ | I don't know why it's called "ProgressIndicator" and not "ProgressBar". |
This is a list of Mathematica tips and tricks.
Often you want something like this:
Position[mylist,#!=0&]
which is not syntactically correct in Mathematica (this syntax works in Select[] for instance, but not in Cases[], to me it's a bit inconsistent).
The following almost works:
Position[mylist,Expect[0]]
but it finds the head of your list and apparently other things as well, so you get results like {0}.
It's better to process mylist directly:
Position[#!=0&/@mylist,True]
Use before any (long) loop over $i$:
ProgressIndicator[Dynamic[i], {imin, imax}]
I don't know why it's called "ProgressIndicator" and not "ProgressBar".