Tips and tricks: Difference between revisions

Jump to navigation Jump to search
1,652 bytes added ,  29 October 2017
(12 intermediate revisions by 10 users not shown)
Line 1: Line 1:
==Preferences==
==Preferences==
Sometimes, Octave defaults are not teh best for someone's specific use. To change the defaults, use the following on the {{Path|.octaverc}} file.
Sometimes, Octave defaults are not the best for someone's specific use. To change the defaults, use the following on the {{Path|[[.octaverc]]}} file.


=== Changing default figure size ===
=== Changing default figure size ===
Line 7: Line 7:
{{Code|change default figure size|<pre>set (0, 'DefaultFigurePosition', [1 get(0, "screensize")(4:-1:3) get(0, "DefaultFigurePosition")(4)]);</pre>}}
{{Code|change default figure size|<pre>set (0, 'DefaultFigurePosition', [1 get(0, "screensize")(4:-1:3) get(0, "DefaultFigurePosition")(4)]);</pre>}}


The value of {{Codeline|DefaultFigurePosition}} must be a four element vector with the x and y coordinates for the figure, followed by its with and height. The code above sets the default image to be placed at the top of the monitor, with the width of the monitor and the same height previously set as default.
The value of {{Codeline|DefaultFigurePosition}} must be a four element vector with the x and y coordinates for the figure, followed by its width and height. The code above sets the default image to be placed at the top of the monitor, with the width of the monitor and the same height previously set as default.
 
=== Changing default font for axes ===
 
To display tex characters such as '\alpha' or '\lambda', a TrueType font ("arial" for instance) is better for the gnuplot backend [https://savannah.gnu.org/bugs/?30681]
{{Code|change default axes font name|<pre>set (0, "DefaultAxesFontName", "Arial")</pre>}}
It can then be necessary to change the font size as well
{{Code|change default axes font size|<pre>set(0, 'DefaultAxesFontSize', 10)</pre>}}
 
 
=== Shorten help message ===
To get rid of the long help message with the link to the Octave homepage place this in your startup file usually at ~/.octaverc (if it does not exist, create it). See the [http://www.gnu.org/software/octave/doc/interpreter/Startup-Files.html documentation] for more information.
suppress_verbose_help_message(1)


==Tiny helper functions==
==Tiny helper functions==
Line 47: Line 59:
=== replace help with man ===
=== replace help with man ===


If you use octave too much, you'll find yourself trying to use {{Codeline|help}} instead of {{Codeline|man}} on bash. This function will fix that so you can use {{Codeline|man}} in your octave instance (you can also do the opposite, create a {{Codeline|help}} alias in bash but {{Codeline|man}} has less characters).
If you use octave too much, you'll find yourself trying to use {{Codeline|help}} instead of {{Codeline|man}} on bash. This function will fix that so you can use {{Codeline|man}} in your octave instance (you can also do the opposite, create a {{Codeline|help}} alias in bash but {{Codeline|man}} has fewwer characters).


{{Code|alias to help|<pre>
{{Code|alias to help|<pre>
Line 66: Line 78:
<tr><td>element multiplication</td><td><code>A.*B</code></td><td><code>product(A,B) </code></td></tr>
<tr><td>element multiplication</td><td><code>A.*B</code></td><td><code>product(A,B) </code></td></tr>
<tr><td>element division</td><td><code>A./B</code></td><td><code>quotient(A,B) </code></td></tr>
<tr><td>element division</td><td><code>A./B</code></td><td><code>quotient(A,B) </code></td></tr>
<tr><td>transpose*</td><td><code>A'</code></td><td><code>A.transpose()</code></td></tr>
<tr><td>transpose*</td><td><code>A.'</code></td><td><code>A.transpose()</code></td></tr>
<tr><td>select element m,n of A**</td><td><code>A(m,n)</code></td><td><code>A(m-1,n-1)</code></td></tr>
<tr><td>select element m,n of A**</td><td><code>A(m,n)</code></td><td><code>A(m-1,n-1)</code></td></tr>
<tr><td>select row N of A**</td><td><code>A(N,:)</code></td><td><code>A.row(N-1)</code></td></tr>
<tr><td>select row N of A**</td><td><code>A(N,:)</code></td><td><code>A.row(N-1)</code></td></tr>
Line 101: Line 113:
<tr><td>number of rows</td><td><code>size(A,1)</code></td><td><code>A.rows()</code></td></tr>
<tr><td>number of rows</td><td><code>size(A,1)</code></td><td><code>A.rows()</code></td></tr>
<tr><td>number of columns</td><td><code>size(A,2)</code></td><td><code>A.cols()</code></td></tr>
<tr><td>number of columns</td><td><code>size(A,2)</code></td><td><code>A.cols()</code></td></tr>
<tr><td>range</td><td><code>0.1:0.2:0.9</code></td><td><code>Range (0.1, 0.9, 0.2).matrix_value ()</code></td></tr>
</table>
</table>


Line 159: Line 172:
*MATLAB array manipulation tips and tricks by Peter Acklam: http://home.online.no/~pjacklam/matlab/doc/mtt/index.html
*MATLAB array manipulation tips and tricks by Peter Acklam: http://home.online.no/~pjacklam/matlab/doc/mtt/index.html
*The MathWorks: Code Vectorization Guide: http://www.mathworks.com/support/tech-notes/1100/1109.html
*The MathWorks: Code Vectorization Guide: http://www.mathworks.com/support/tech-notes/1100/1109.html
[[Category:Tips and tricks]]
===Changing BLAS===
Many Octave functions are wrappers to optimized numerical libraries, notably BLAS and ATLAS. It is possible to achieve impressive performance gains by simply using a library tuned to your platform. One example is using OpenBLAS to replace the default BLAS implementation ([http://www.stat.cmu.edu/~nmv/2013/07/09/for-faster-r-use-openblas-instead-better-than-atlas-trivial-to-switch-to-on-ubuntu/ further details]).
On some Linux distributions, this just takes a few commands. For instance, on Ubuntu, it usually suffices to run
sudo apt-get install libopenblas-base libatlas3gf-base
followed by
sudo update-alternatives --config libblas.so.3
and then selecting the openblas option.
219

edits

Navigation menu