Mercurial > octave-nkf
annotate doc/faq/OctaveFAQ.texi @ 12479:c741c1f2789e
Minor proofreading in FAQ
author | Jordi Gutiérrez Hermoso <jordigh@gmail.com> |
---|---|
date | Fri, 25 Feb 2011 15:11:26 -0600 |
parents | b4138a75eecc |
children | 30f2a3b1d236 |
rev | line source |
---|---|
11523 | 1 % Copyright (C) 1997-2011 John W. Eaton |
7018 | 2 % |
3 % This file is part of Octave. | |
4 % | |
5 % Octave is free software; you can redistribute it and/or modify it | |
6 % under the terms of the GNU General Public License as published by the | |
7 % Free Software Foundation; either version 3 of the License, or (at | |
8 % your option) any later version. | |
9 % | |
10 % Octave is distributed in the hope that it will be useful, but WITHOUT | |
11 % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 % FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 % for more details. | |
14 % | |
15 % You should have received a copy of the GNU General Public License | |
16 % along with Octave; see the file COPYING. If not, see | |
17 % <http://www.gnu.org/licenses/>. | |
18 | |
2866 | 19 \input texinfo.tex @c -*-texinfo-*- |
20 | |
9794
0d4613a736e9
convert build system to use automake and libtool
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
21 @setfilename OctaveFAQ.info |
2866 | 22 @settitle Frequently asked questions about Octave (with answers) |
23 | |
24 @setchapternewpage off | |
5099 | 25 @direntry |
9794
0d4613a736e9
convert build system to use automake and libtool
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
26 * OctaveFAQ: (OctaveFAQ). Frequently asked questions about Octave |
5099 | 27 @end direntry |
2866 | 28 @titlepage |
29 @title Octave FAQ | |
30 @subtitle Frequently asked questions about Octave | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
31 @subtitle @today{} |
2866 | 32 @sp 1 |
6900 | 33 @author John W. Eaton and David Bateman |
2866 | 34 @page |
35 @end titlepage | |
36 | |
5423 | 37 @ifnottex |
4830 | 38 @node Top |
2866 | 39 @top |
40 @unnumbered Preface | |
41 @cindex FAQ for Octave, latest version | |
5423 | 42 @end ifnottex |
2866 | 43 |
44 This is a list of frequently asked questions (FAQ) for Octave users. | |
45 | |
6584 | 46 We are always looking for new questions (@emph{with} answers), better |
47 answers, or both. Please send suggestions to @email{bug@@octave.org}. | |
48 If you have general questions about Octave, or need help for something | |
49 that is not covered by the Octave manual or the FAQ, please use the | |
50 @email{help@@octave.org} mailing list. | |
2866 | 51 |
52 This FAQ is intended to supplement, not replace, the Octave manual. | |
6584 | 53 Before posting a question to the @email{help@@octave.org} mailing list, |
54 you should first check to see if the topic is covered in the manual. | |
2866 | 55 |
56 @menu | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
57 * What is Octave?:: |
9076 | 58 * Licensing Issues:: |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
59 * How can I cite Octave?:: |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
60 * Series 3.0.N:: |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
61 * Octave Features:: |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
62 * Learning more about Octave:: |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
63 * Getting Octave:: |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
64 * Installation:: |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
65 * Common problems:: |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
66 * How do I ...?:: |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
67 * @sc{Matlab} compatibility:: |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
68 * Index:: |
2866 | 69 @end menu |
70 | |
4830 | 71 @node What is Octave? |
2866 | 72 @chapter What is Octave? |
73 | |
74 Octave is a high-level interactive language, primarily intended for | |
75 numerical computations that is mostly compatible with | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
76 @sc{Matlab}.@footnote{@sc{Matlab} is a registered trademark of The |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
77 MathWorks, Inc.} |
2866 | 78 |
6583 | 79 Octave can do arithmetic for real, complex or integer-valued scalars |
80 and matrices, solve sets of nonlinear algebraic equations, integrate | |
81 functions over finite and infinite intervals, and integrate systems of | |
82 ordinary differential and differential-algebraic equations. | |
2866 | 83 |
84 Octave uses the GNU readline library to handle reading and editing | |
85 input. By default, the line editing commands are similar to the | |
86 cursor movement commands used by GNU Emacs, and a vi-style line | |
87 editing interface is also available. At the end of each session, the | |
88 command history is saved, so that commands entered during previous | |
89 sessions are not lost. | |
90 | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
91 The Octave distribution includes a 590+ page Texinfo manual. Access to |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
92 the complete text of the manual is available via the @code{doc} command |
2866 | 93 at the Octave prompt. |
94 | |
6583 | 95 @menu |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
96 * Who develops Octave?:: |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
97 * Why GNU Octave?:: |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
98 * What version should I use?:: |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
99 * On what platforms does Octave run?:: |
6583 | 100 @end menu |
101 | |
102 @node Who develops Octave? | |
103 @section Who develops Octave? | |
104 | |
6584 | 105 Discussions about writing the software that would eventually become |
106 Octave started in about 1988 with James B. Rawlings and John W. Eaton at | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
107 the University of Texas. John W. Eaton was the original author of |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
108 Octave, starting full-time development in February 1992. He is still the |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
109 primary maintainer. The community of users/developers has in addition |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
110 contributed some code and fuels the discussion on the mailing lists |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
111 @email{help@@octave.org} (user forum), @email{maintainers@@octave.org} |
6584 | 112 (development issues), and @email{octave-dev@@lists.sourceforge.net} (all |
113 things related to the Octave Forge repository of user-contributed | |
114 functions). | |
6583 | 115 |
6584 | 116 @node Why GNU Octave? |
117 @section Why GNU Octave? | |
6583 | 118 |
6584 | 119 The GNU Project was launched in 1984 to develop a complete Unix-like |
120 operating system which is free software: the GNU system. | |
121 | |
122 GNU is a recursive acronym for ``GNU's Not Unix''; it is pronounced | |
123 guh-noo, approximately like canoe. | |
6583 | 124 |
6584 | 125 The Free Software Foundation (FSF) is the principal organizational |
126 sponsor of the GNU Project. | |
127 | |
128 Octave became GNU Octave in 1997 (beginning with version 2.0.6). This | |
129 meant agreeing to consider Octave a part of the GNU Project and support | |
130 the efforts of the FSF. However, Octave is not and has never been | |
131 developed by the FSF. | |
132 | |
133 For more information about the GNU project, see @url{www.gnu.org}. | |
6583 | 134 |
135 @cindex FSF [Free Software Foundation] | |
136 @cindex GNU [GNU's not unix] | |
137 | |
138 @node What version should I use? | |
139 @section What version should I use? | |
140 | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
141 In general, you will find the latest version on |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
142 @url{http://www.octave.org/download.html}. It is recommended to use the |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
143 ``testing'' version of octave for general use, and the ``development'' |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
144 version if you want the latest features. |
6583 | 145 |
146 A list of user-visible changes since the last release is available in | |
147 the file @file{NEWS}. The file @file{ChangeLog} in the source | |
148 distribution contains a more detailed record of changes made since the | |
149 last release. | |
150 | |
151 @node On what platforms does Octave run? | |
152 @section On what platforms does Octave run? | |
153 | |
6584 | 154 Octave runs on various Unices---at least Linux and Solaris, Mac OS X, |
155 Windows and anything you can compile it on. Binary distributions exist | |
6583 | 156 at least for Debian, Suse, Fedora and RedHat Linuxes (Intel and AMD |
157 CPUs, at least), for Mac Os X and Windows' 98, 2000 and XP. | |
158 | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
159 Two and three dimensional plotting is fully supported using gnuplot and |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
160 an experimental OpenGL backend. |
2866 | 161 |
162 The underlying numerical solvers are currently standard Fortran ones | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
163 like LAPACK, LINPACK, ODEPACK, the BLAS, etc., packaged in a library |
2866 | 164 of C++ classes. If possible, the Fortran subroutines are compiled |
165 with the system's Fortran compiler, and called directly from the C++ | |
166 functions. If that's not possible, you can still compile Octave if | |
167 you have the free Fortran to C translator f2c. | |
168 | |
169 Octave is also free software; you can redistribute it and/or modify it | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
170 under the terms of the GNU General Public License, version 3, as |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
171 published by the Free Software Foundation, or at your option any later |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
172 version. |
2866 | 173 |
9076 | 174 @node Licensing Issues |
175 @chapter Licensing Issues | |
176 | |
177 @menu | |
178 * If I write code using Octave do I have to release it under the GPL?: GPL | |
179 * Since the MEX interface allows plugins to be distributed under terms that are incompatible with the GPL, does this mean that you are encouraging people to to write non-free software for Octave?: Licensing MEX Files | |
180 * I wrote a program that links with Octave libraries and I don't want to release it under the terms of the GPL. Will you change the license of the Octave libraries for me?: Requesting License Changes | |
181 @end menu | |
182 | |
183 @node GPL | |
184 @section If I write code using Octave do I have to release it under the GPL? | |
185 | |
186 The answer depends on precisely how the code is written and how it works. | |
187 | |
188 Code written entirely in the scripting language of Octave | |
189 (interpreted code in .m files) may be released under the terms of | |
190 whatever license you choose. | |
191 | |
192 Code written using Octave's native plug-in interface (also known | |
193 as a .oct file) necessarily links with Octave internals and is | |
194 considered a derivative work of Octave and therefore must be | |
195 released under terms that are compatible with the GPL. | |
196 | |
12478
b4138a75eecc
Uniformise "Matlab" typesetting in FAQ.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11576
diff
changeset
|
197 Code written using Octave's implementation of the @sc{Matlab} MEX |
9076 | 198 interface may be released under the terms of whatever license you |
199 choose, provided that the following conditions are met: | |
200 | |
201 @enumerate | |
202 @item | |
203 The plugin should not use any bindings that are specific to Octave. In | |
204 other words, the MEX file must use the MEX interface only, and not also | |
205 call on other Octave internals. It should be possible in principle to | |
206 use the MEX file with other programs that implement the MEX interface | |
12478
b4138a75eecc
Uniformise "Matlab" typesetting in FAQ.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11576
diff
changeset
|
207 (e.g., @sc{Matlab}). |
9076 | 208 |
209 @item | |
210 The MEX file should not be distributed together with Octave in such a | |
211 way that they effectively create a single work. For example, you should | |
212 not distribute the MEX file and Octave together in a single package such | |
213 that Octave automatically loads and runs the MEX file when it starts up. | |
214 There are other possible ways that you might effectively create a single | |
215 work; this is just one example. | |
216 @end enumerate | |
217 | |
218 A program that embeds the Octave interpreter (e.g., by calling the | |
219 "octave_main" function), or that calls functions from Octave's | |
220 libraries (e.g., liboctinterp, liboctave, or libcruft) is | |
221 considered a derivative work of Octave and therefore must be | |
222 released under terms that are compatible with the GPL. | |
223 | |
224 @node Licensing MEX Files | |
225 @section Since the MEX interface allows plugins to be distributed under terms that are incompatible with the GPL, does this mean that you are encouraging people to to write non-free software for Octave? | |
226 | |
227 No. The original reason for implementing the MEX interface for Octave | |
228 was to allow Octave to run free software that uses MEX files (the | |
229 particular goal was to run SundialsTB in Octave). The intent was to | |
12478
b4138a75eecc
Uniformise "Matlab" typesetting in FAQ.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11576
diff
changeset
|
230 liberate that software from @sc{Matlab} and increase the amount of free |
9076 | 231 software available to Octave users, not to enable people to write |
232 proprietary code for Octave. For the good of the community, we strongly | |
233 encourage users of Octave to release the code they write for Octave | |
234 under terms that are compatible with the GPL. | |
235 | |
236 @node Requesting License Changes | |
237 @section I wrote a program that links with Octave libraries and I don't want to release it under the terms of the GPL. Will you change the license of the Octave libraries for me? | |
238 | |
239 No. Instead of asking us to change the licensing terms for Octave, we | |
240 recommend that you release your program under terms that are compatible | |
241 with the GPL so that the free software community can benefit from your | |
242 work the same as you have benefitted from the work of all the people who | |
243 have contributed to Octave. | |
244 | |
4830 | 245 @node How can I cite Octave? |
246 @chapter How can I cite Octave? | |
4831 | 247 |
248 Pointing to @url{http://www.octave.org} is good, because that gives | |
249 people a direct way to find out more. If citation of a URL is not | |
250 allowed by a publisher, or if you also want to point to a traditional | |
251 reference, then you can cite the Octave manual: | |
4830 | 252 |
253 @example | |
254 @group | |
8334 | 255 @@BOOK@{eaton:2008, |
256 author = "John W. Eaton and David Bateman and Søren Hauberg", | |
257 title = "GNU Octave Manual Version 3", | |
6584 | 258 publisher = "Network Theory Limited", |
8334 | 259 year = "2008", |
260 isbn = "0-9546120-6-X" | |
6584 | 261 @} |
4830 | 262 @end group |
263 @end example | |
264 | |
8128 | 265 @node Series 3.0.N |
266 @chapter What's new in version series 3.0.N and 3.1.N of Octave | |
6583 | 267 |
8128 | 268 The 3.0.N series has enough new features to justify a major version |
269 number change. The 3.0.N series brings | |
6583 | 270 |
271 @itemize @bullet | |
272 | |
273 @item integer types | |
274 | |
275 @item fixed point arithmetic | |
276 | |
277 @item sparse matrices | |
278 | |
279 @item Linear programming code based on GLPK | |
280 | |
281 @item 64-bit compilation support | |
282 | |
12478
b4138a75eecc
Uniformise "Matlab" typesetting in FAQ.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11576
diff
changeset
|
283 @item gzipped files and stream and consequently support of @sc{Matlab} v7 files |
2866 | 284 |
6583 | 285 @item better support for both msvc and mingw |
286 | |
7116 | 287 @item a fully compatible MEX interface |
6583 | 288 |
6606 | 289 @item many many other minor features and compatibility changes |
6583 | 290 |
291 @end itemize | |
292 | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
293 Here are some features that have been around since 2.1.N: |
6583 | 294 |
295 @itemize @bullet | |
2866 | 296 |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
297 @item NDarrays |
6583 | 298 |
299 @item cells | |
300 | |
301 @end itemize | |
302 | |
8128 | 303 The 3.1.N series is the current development release and will become a |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
304 3.2.N release in the future. This series brings the following new |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
305 features: |
8128 | 306 |
307 @itemize | |
11576
8ac9687dbe9f
rename backend to graphics_toolkit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
308 @item OpenGL graphics toolkit |
8128 | 309 |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
310 An experimental OpenGL graphics toolkit to replace gnuplot. |
8128 | 311 |
312 @item Object Orient Programming | |
313 | |
314 @item Block comments | |
315 | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
316 @item imwrite and imread |
8128 | 317 |
318 The functions are based on the GraphicsMagick library. | |
319 | |
320 @item Lazy transpose | |
321 | |
322 Special treatment in the parser of things like "a' * b", where the | |
323 transpose is never explicitly formed but a flag is rather passed to the | |
324 underlying LAPACK code. | |
325 | |
326 @item Single precision type | |
8292 | 327 |
328 @item Improved array indexing | |
329 The underlying code used for indexing of arrays has been completely | |
330 rewritten and so the indexing of arrays is now significantly faster. | |
8128 | 331 @end itemize |
332 | |
333 | |
4830 | 334 @node Octave Features |
2866 | 335 @chapter What features are unique to Octave? |
336 | |
337 @menu | |
6583 | 338 * Functions defined on the command-line:: |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
339 * Comments with #:: |
6583 | 340 * Strings delimitted by double quotes ":: |
341 * Line continuation by backslash:: | |
342 * Informative block closing:: | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
343 * Coherent syntax:: |
6583 | 344 * Exclamation mark as not operator:: |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
345 * Increment and decrement operators:: |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
346 * Unwind-protect:: |
6583 | 347 * Built-in ODE and DAE solvers:: |
2866 | 348 @end menu |
349 | |
12478
b4138a75eecc
Uniformise "Matlab" typesetting in FAQ.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11576
diff
changeset
|
350 This section refers to @sc{Matlab} R2008b and Octave 2.1.51. |
2866 | 351 |
6583 | 352 @node Functions defined on the command-line |
353 @section Functions defined on the command-line | |
2866 | 354 |
6583 | 355 Functions can be defined by entering code on the command line, a |
6584 | 356 feature not supported by the other leading brand. For example, you may |
6583 | 357 type: |
2866 | 358 |
359 @example | |
360 @group | |
6583 | 361 octave:1> function s = hello_string (to_who) |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
362 > ## Say hello |
6583 | 363 > if nargin<1, to_who = "World"; end |
364 > s = ["Hello ",\ | |
365 > to_who]; | |
366 > endfunction | |
367 octave:2> hello_string ("Moon") | |
368 ans = Hello Moon | |
2866 | 369 @end group |
370 @end example | |
371 | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
372 @node Comments with # |
6583 | 373 @section Comments with # |
374 | |
6584 | 375 The pound character, @samp{#}, may be used to start comments, in addition |
376 to @samp{%}. See the previous example. The major advantage of this is | |
377 that as @samp{#} is also a comment character for unix script files, any | |
378 file that starts with a string like @samp{#! /usr/bin/octave -q} will be | |
379 treated as an octave script and be executed by octave. | |
2866 | 380 |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
381 @node Strings delimitted by double quotes " |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
382 @section Strings delimitted by double quotes " |
6584 | 383 The double quote, @samp{"}, may be used to delimit strings, in addition to |
384 the single quote @samp{'}. See the previous example. Also, double-quoted | |
385 strings include backslash interpretation (like C++, C, and Perl) while | |
12478
b4138a75eecc
Uniformise "Matlab" typesetting in FAQ.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11576
diff
changeset
|
386 single quoted are uninterpreted (like @sc{Matlab} and Perl). |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
387 |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
388 @node Line continuation by backslash |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
389 @section Line continuation by backslash |
6583 | 390 |
6584 | 391 Lines can be continued with a backslash, @samp{\}, in addition to three |
392 points @samp{@dots{}}. See the previous example. | |
6583 | 393 |
394 @node Informative block closing | |
395 @section Informative block closing | |
396 | |
6584 | 397 You may close @code{function}, @code{for}, @code{while}, @code{if}, |
398 @dots{} blocks with @code{endfunction}, @code{endfor}, @code{endwhile}, | |
12478
b4138a75eecc
Uniformise "Matlab" typesetting in FAQ.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11576
diff
changeset
|
399 @dots{} keywords in addition to using @code{end}. As with @sc{Matlab}, the |
6584 | 400 @code{end} (or @code{endfunction}) keyword that marks the end of a |
401 function defined in a @file{.m} file is optional. | |
2866 | 402 |
6583 | 403 @node Coherent syntax |
404 @section Coherent syntax | |
405 | |
406 Indexing other things than variables is possible, as in: | |
407 @example | |
408 @group | |
409 octave:1> [3 1 4 1 5 9](3) | |
410 ans = 4 | |
411 octave:2> cos([0 pi pi/4 7])(3) | |
412 ans = 0.70711 | |
413 @end group | |
414 @end example | |
415 | |
416 @node Exclamation mark as not operator | |
417 @section Exclamation mark as not operator | |
418 | |
419 The exclamation mark '!' (aka ``Bang!'') is a negation operator, just | |
420 like the tilde '~': | |
2866 | 421 |
422 @example | |
423 @group | |
6583 | 424 octave:1> if ! strcmp (program_name, "octave"), |
425 > "It's an error" | |
426 > else | |
427 > "It works!" | |
428 > end | |
429 ans = It works! | |
2866 | 430 @end group |
431 @end example | |
432 | |
4830 | 433 @node Increment and decrement operators |
2866 | 434 @section Increment and decrement operators |
435 | |
436 @cindex Increment operators | |
437 @cindex Decrement operators | |
438 @cindex Operators, increment | |
439 @cindex Operators, decrement | |
440 | |
6584 | 441 If you like the @samp{++}, @samp{+=} etc operators, rejoice! |
2866 | 442 Octave includes the C-like increment and decrement operators @samp{++} |
6583 | 443 and @samp{--} in both their prefix and postfix forms, in addition to |
444 @samp{+=}, @samp{-=}, @samp{*=}, @samp{/=}, @samp{^=}, @samp{.*=}, | |
445 @samp{./=}, and @samp{.^=}. | |
2866 | 446 |
447 For example, to pre-increment the variable @var{x}, you would write | |
448 @code{++@var{x}}. This would add one to @var{x} and then return the new | |
449 value of @var{x} as the result of the expression. It is exactly the | |
450 same as the expression @code{@var{x} = @var{x} + 1}. | |
451 | |
6584 | 452 To post-increment a variable @var{x}, you would write @code{x++}. |
2866 | 453 This adds one to the variable @var{x}, but returns the value that |
454 @var{x} had prior to incrementing it. For example, if @var{x} is equal | |
6584 | 455 to 2, the result of the expression @code{x++} is 2, and the new |
2866 | 456 value of @var{x} is 3. |
457 | |
458 For matrix and vector arguments, the increment and decrement operators | |
459 work on each element of the operand. | |
460 | |
4830 | 461 @node Unwind-protect |
2866 | 462 @section Unwind-protect |
463 | |
464 @cindex Unwind-protect | |
465 | |
466 Octave supports a limited form of exception handling modelled after the | |
467 unwind-protect form of Lisp. The general form of an | |
468 @code{unwind_protect} block looks like this: | |
469 | |
470 @example | |
471 @group | |
472 unwind_protect | |
473 @var{body} | |
474 unwind_protect_cleanup | |
475 @var{cleanup} | |
476 end_unwind_protect | |
477 @end group | |
478 @end example | |
479 | |
480 @noindent | |
481 Where @var{body} and @var{cleanup} are both optional and may contain any | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
482 Octave expressions or commands. The statements in @var{cleanup} are |
2866 | 483 guaranteed to be executed regardless of how control exits @var{body}. |
484 | |
485 The @code{unwind_protect} statement is often used to reliably restore | |
486 the values of global variables that need to be temporarily changed. | |
487 | |
12478
b4138a75eecc
Uniformise "Matlab" typesetting in FAQ.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11576
diff
changeset
|
488 @sc{Matlab} can be made to do something similar with their @code{OnCleanUp} |
8128 | 489 function that was introduced in 2008a. |
490 | |
4830 | 491 @node Built-in ODE and DAE solvers |
2866 | 492 @section Built-in ODE and DAE solvers |
493 | |
494 @cindex DASSL | |
495 @cindex LSODE | |
496 | |
497 Octave includes LSODE and DASSL for solving systems of stiff ordinary | |
498 differential and differential-algebraic equations. These functions are | |
499 built in to the interpreter. | |
500 | |
6583 | 501 @node Learning more about Octave |
502 @chapter What documentation exists for Octave? | |
503 | |
504 @menu | |
505 * Documentation:: | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
506 * Getting additional help:: |
6583 | 507 * User community:: |
508 * Bug reports:: | |
509 @end menu | |
510 | |
4830 | 511 @node Documentation |
6583 | 512 @section What documentation exists for Octave? |
2866 | 513 |
514 @cindex Octave, documentation | |
515 | |
6879 | 516 The Octave distribution includes a 590+ page manual that is also |
2866 | 517 distributed under the terms of the GNU GPL. |
6583 | 518 It is available on the web at |
519 @url{http://www.octave.org/docs.html} and you will also | |
520 find there instructions on how to order a paper version. | |
521 | |
522 The complete text of the Octave manual is also available using the GNU | |
523 Info system via the GNU Emacs, info, or xinfo programs, or by using | |
524 the @samp{help -i} command to start the GNU info browser directly from | |
525 the Octave prompt. | |
526 | |
527 If you have problems using this documentation, or find that some topic | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
528 is not adequately explained, indexed, or cross-referenced, please report |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
529 it on @url{http://bugs.octave.org}. |
2866 | 530 |
6583 | 531 @node Getting additional help |
532 @section Getting additional help | |
533 | |
534 @cindex Additional help | |
535 @cindex Mailing lists, help-octave | |
536 | |
6584 | 537 If you can't find an answer to your question, the |
538 @email{help@@octave.org} mailing list is available for questions related | |
539 to using, installing, and porting Octave that are not adequately | |
540 answered by the Octave manual or by this document. | |
6583 | 541 |
542 @node User community | |
543 @section User community | |
544 | |
6584 | 545 To subscribe to the list, go to @url{www.octave.org/archive.html} and |
546 follow the link to the subscription page for the list. | |
2866 | 547 |
6653 | 548 @strong{Please do not} send requests to be added or removed from the |
6583 | 549 mailing list, or other administrative trivia to the list itself. |
550 | |
551 An archive of old postings to the help-octave mailing list is maintained | |
552 on @url{http://www.octave.org/archive.html}. | |
553 | |
6584 | 554 You will also find some user advice and code spread over the web. Good |
6583 | 555 starting points are the Octave Wiki @url{http://wiki.octave.org} and |
7483
fb66330b2608
don't special case SH_LD for FreeBSD and OpenBSD
John W. Eaton <jwe@octave.org>
parents:
7116
diff
changeset
|
556 Octave-Forge @url{http://octave.sourceforge.net} |
6583 | 557 |
558 @node Bug reports | |
559 @section I think I have found a bug in Octave. | |
560 | |
561 @cindex Bug in Octave, newly found | |
562 | |
563 ``I think I have found a bug in Octave, but I'm not sure. How do I know, | |
564 and who should I tell?'' | |
2866 | 565 |
6583 | 566 @cindex Manual, for Octave |
567 | |
568 First, see the section on bugs and bug reports in the Octave manual. | |
569 When you report a bug, make sure to describe the type of computer you | |
570 are using, the version of the operating system it is running, and the | |
571 version of Octave that you are using. Also provide enough code so that | |
572 the Octave maintainers can duplicate your bug. | |
573 | |
574 If you have Octave working at all, the easiest way to do this is to use | |
575 the Octave function @code{bug_report}. When you execute this function, | |
576 Octave will prompt you for a subject and then invoke the editor on a | |
577 file that already contains all the configuration information. When you | |
578 exit the editor, Octave will mail the bug report for you (in a unix-like | |
579 operating system). | |
580 | |
581 @cindex Octave bug report | |
582 @cindex Mailing lists, bug-octave | |
583 | |
584 If for some reason you cannot use Octave's @code{bug_report} function, | |
6584 | 585 mail your bug report to @email{bug@@octave.org}. Your message needs to |
6583 | 586 include enough information to allow the maintainers of Octave to fix the |
587 bug. Please read the section on bugs and bug reports in the Octave | |
588 manual for a list of things that should be included in every bug report. | |
589 | |
2866 | 590 |
4830 | 591 @node Getting Octave |
6583 | 592 @chapter Getting Octave |
2866 | 593 |
594 @menu | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
595 * Source code:: |
6583 | 596 * Pre-compiled binary packages:: |
597 * Octave for other platforms:: | |
2866 | 598 @end menu |
599 | |
6583 | 600 @node Source code |
601 @section Source code | |
602 @cindex Source code | |
2866 | 603 |
6583 | 604 Source code is available on the Octave development site, where you are |
605 sure to get the latest version. | |
2866 | 606 |
6583 | 607 @itemize @bullet |
608 @item @url{http://www.octave.org/download.html} | |
609 @item @url{ftp://ftp.octave.org/pub/octave/} | |
610 @end itemize | |
2866 | 611 |
6583 | 612 Since Octave is distrubted under the terms of the GPL, you can get |
613 Octave from a friend who has a copy, by anonymous FTP, or by ordering | |
614 a tape or CD-ROM from the Free Software Foundation (FSF). | |
2866 | 615 |
6583 | 616 @node Pre-compiled binary packages |
617 @section Pre-compiled binary packages | |
618 @cindex Pre-compiled binary packages | |
619 @cindex Binaries | |
2866 | 620 |
6584 | 621 The Octave project does not distribute binary packages, but other |
622 projects do. For an up-to-date listing of packagers, see: | |
2866 | 623 |
6583 | 624 @itemize @bullet |
625 @item @url{http://www.octave.org/download.html} | |
626 @item @url{http://wiki.octave.org/wiki.pl?CategoryInstall} | |
627 @end itemize | |
2866 | 628 |
6583 | 629 As of today, Octave binaries are available at least on Debian, RedHat, |
630 Suse and Fedora Linuxes, Mac OS X, Windows' 98, 2000 and XP. | |
2866 | 631 |
4830 | 632 @node Octave for other platforms |
2866 | 633 @section How do I get a copy of Octave for (some other platform)? |
634 | |
635 @cindex VMS support | |
636 @cindex VAX | |
637 @cindex MS-DOS support | |
3154 | 638 @cindex Windows support |
2866 | 639 @cindex DJGPP |
640 @cindex EMX | |
641 @cindex OS/2 support | |
642 | |
6879 | 643 Octave currently runs on Unix-like systems, Mac OS X, and Windows. |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
644 It should be possible to make Octave work on other systems as well. |
6879 | 645 If you are interested in porting Octave to other systems, please contact |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
646 @email{maintainers@@octave.org}. |
2866 | 647 |
6583 | 648 @c @menu |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
649 @c * Octave for Unix:: |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
650 @c * Octave for other platforms:: |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
651 @c * latest versions:: |
6583 | 652 @c @end menu |
2866 | 653 |
6583 | 654 @c @cindex Octave, ordering |
655 @c @cindex Octave, getting a copy | |
2866 | 656 |
4830 | 657 @node Installation |
2866 | 658 @chapter Installation Issues and Problems |
659 | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
660 @cindex Octave, building |
2866 | 661 |
8128 | 662 Octave 3.2 require approximately 800MB of disk storage to unpack |
6584 | 663 and compile from source (considerably less if you don't compile with |
664 debugging symbols). Once installed, Octave requires approximately 200MB | |
665 of disk space (again, considerably less if you don't compile with | |
666 debugging symbols). | |
2866 | 667 |
668 @menu | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
669 * What else do I need?:: |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
670 * Other C++ compilers?:: |
2866 | 671 @end menu |
672 | |
4830 | 673 @node What else do I need? |
2866 | 674 @section What else do I need? |
675 | |
676 @cindex GNU gcc | |
677 @cindex GNU g++ | |
678 @cindex libg++ | |
679 @cindex GNU Make | |
680 @cindex Flex | |
681 @cindex GNU Bison | |
682 | |
3154 | 683 To compile Octave, you will need a recent version of GNU Make. You |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
684 will also need GCC 3.3 or later, although GCC 4.1 or later is |
6584 | 685 recommended. |
3154 | 686 |
6584 | 687 @strong{You must have GNU Make to compile octave}. Octave's Makefiles |
3154 | 688 use features of GNU Make that are not present in other versions of make. |
689 GNU Make is very portable and easy to install. | |
2866 | 690 |
4830 | 691 @node Other C++ compilers? |
2866 | 692 @section Can I compile Octave with another C++ compiler? |
693 | |
6584 | 694 Yes, but development is done primarily with GCC, so you may hit some |
695 incompatibilities. Octave is intended to be portable to any standard | |
696 conforming compiler. If you have difficulties that you think are bugs, | |
697 please report them to the @email{bug@@octave.org} mailing list, or ask | |
698 for help on the @email{help@@octave.org} mailing list. | |
2866 | 699 |
4830 | 700 @node Common problems |
2866 | 701 @chapter Common problems |
702 | |
703 This list is probably far too short. Feel free to suggest additional | |
704 questions (preferably with answers!) | |
705 | |
706 @itemize @bullet | |
707 @item | |
708 Octave takes a long time to find symbols. | |
709 | |
6606 | 710 Octave uses the @code{genpath} function to recursively add directories |
6900 | 711 to the list of directories searched for function files. Check the list |
6606 | 712 of directories with the @code{path} command. If the path list is very |
713 long check your use of the @code{genpath} function. | |
6735 | 714 |
715 @item | |
6900 | 716 When plotting Octave occasionally gives me errors like @samp{gnuplot> 9 0.735604 |
717 line 26317: invalid command}. | |
6735 | 718 |
719 There is a known bug in gnuplot 4.2 that can cause an off by one error | |
720 while piping data to gnuplot. The relevant gnuplot bug report can be | |
721 found at @url{http://sourceforge.net/tracker/index.php?func=detail&aid=1716556&group_id=2055&atid=102055} | |
722 | |
723 If you have obtained your copy of Octave from a distribution please file | |
724 a bug report requesting that the fix reported in the above bug report be | |
725 included. | |
8215
518789a0539d
FAQ entry about split development packages in distributions
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8130
diff
changeset
|
726 |
518789a0539d
FAQ entry about split development packages in distributions
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8130
diff
changeset
|
727 @item |
518789a0539d
FAQ entry about split development packages in distributions
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8130
diff
changeset
|
728 I cannot install a package. Octave complains about a missing @code{mkoctfile}. |
518789a0539d
FAQ entry about split development packages in distributions
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8130
diff
changeset
|
729 |
518789a0539d
FAQ entry about split development packages in distributions
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8130
diff
changeset
|
730 Most distributions split Octave into several packages. The script |
518789a0539d
FAQ entry about split development packages in distributions
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8130
diff
changeset
|
731 @code{mkoctfile} is then part of a separate package: |
518789a0539d
FAQ entry about split development packages in distributions
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8130
diff
changeset
|
732 @itemize @minus |
518789a0539d
FAQ entry about split development packages in distributions
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8130
diff
changeset
|
733 @item |
518789a0539d
FAQ entry about split development packages in distributions
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8130
diff
changeset
|
734 Debian/Ubuntu |
518789a0539d
FAQ entry about split development packages in distributions
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8130
diff
changeset
|
735 |
518789a0539d
FAQ entry about split development packages in distributions
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8130
diff
changeset
|
736 @code{aptitude install octave3.0-headers} |
518789a0539d
FAQ entry about split development packages in distributions
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8130
diff
changeset
|
737 |
518789a0539d
FAQ entry about split development packages in distributions
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8130
diff
changeset
|
738 @item |
518789a0539d
FAQ entry about split development packages in distributions
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8130
diff
changeset
|
739 Fedora |
518789a0539d
FAQ entry about split development packages in distributions
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8130
diff
changeset
|
740 |
518789a0539d
FAQ entry about split development packages in distributions
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8130
diff
changeset
|
741 @code{yum install octave-devel} |
518789a0539d
FAQ entry about split development packages in distributions
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8130
diff
changeset
|
742 |
518789a0539d
FAQ entry about split development packages in distributions
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8130
diff
changeset
|
743 @end itemize |
2866 | 744 @end itemize |
745 | |
6584 | 746 @node How do I ...? |
747 @chapter How do I ...? | |
2866 | 748 |
6583 | 749 @menu |
750 * How do I set the number of displayed decimals?:: | |
751 @end menu | |
2866 | 752 |
6583 | 753 @cindex Tips and tricks |
6584 | 754 @cindex How do I @dots{} ? |
2866 | 755 |
6583 | 756 @node How do I set the number of displayed decimals? |
757 @section How do I set the number of displayed decimals? | |
2866 | 758 |
759 @example | |
760 @group | |
6583 | 761 octave:1> format long |
762 octave:2> pi | |
763 pi = 3.14159265358979 | |
764 octave:3> format short | |
765 octave:4> pi | |
766 pi = 3.1416 | |
2866 | 767 @end group |
768 @end example | |
769 | |
12478
b4138a75eecc
Uniformise "Matlab" typesetting in FAQ.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11576
diff
changeset
|
770 @node @sc{Matlab} compatibility |
2866 | 771 @chapter Porting programs from @sc{Matlab} to Octave |
772 | |
773 @cindex @sc{Matlab} compatibility | |
774 @cindex Compatibility with @sc{Matlab} | |
775 | |
6612 | 776 People often ask |
777 | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
778 @quotation |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
779 I wrote some code for @sc{Matlab}, and I want to get it running under |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
780 Octave. Is there anything I should watch out for? |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
781 @end quotation |
2866 | 782 |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
783 @noindent |
6612 | 784 or alternatively |
785 | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
786 @quotation |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
787 I wrote some code in Octave, and want to share it with @sc{Matlab} |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
788 users. Is there anything I should watch out for? |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
789 @end quotation |
6612 | 790 |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
791 @noindent |
6900 | 792 which is not quite the same thing. There are still a number of |
6612 | 793 differences between Octave and @sc{Matlab}, however in general |
794 differences between the two are considered as bugs. Octave might | |
795 consider that the bug is in @sc{Matlab} and do nothing about it, but | |
796 generally functionality is almost identical. If you find a difference | |
797 between Octave behavior and @sc{Matlab}, then you should send a | |
798 description of this difference (with code illustrating the difference, | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
799 if possible) to @url{http://bugs.octave.org}. |
6612 | 800 |
12478
b4138a75eecc
Uniformise "Matlab" typesetting in FAQ.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11576
diff
changeset
|
801 Furthermore, Octave adds a few syntactical extensions to @sc{Matlab} that |
b4138a75eecc
Uniformise "Matlab" typesetting in FAQ.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11576
diff
changeset
|
802 might cause some issues when exchanging files between @sc{Matlab} and Octave |
6612 | 803 users. As both Octave and @sc{Matlab} are under constant development the |
804 information in this section is subject to change at anytime. | |
805 | |
806 You should also look at the page | |
807 @url{http://octave.sourceforge.net/packages.html} and | |
808 @url{http://octave.sourceforge.net/doc/} that has a function reference | |
809 that is up to date. You can use this function reference to see the | |
810 number of octave function that are available and their @sc{Matlab} | |
811 compatibility. | |
812 | |
8128 | 813 The major differences between Octave 3.2.N and @sc{Matlab} R2008a are: |
6612 | 814 |
815 @itemize @bullet | |
816 @item Nested Functions | |
817 | |
6900 | 818 Octave doesn't yet have nested functions. That is |
2866 | 819 |
6612 | 820 @example |
821 @group | |
822 function y = foo (x) | |
6900 | 823 y = bar(x) |
824 function y = bar (x) | |
825 y = @dots{}; | |
826 end | |
6612 | 827 end |
828 @end group | |
829 @end example | |
830 | |
831 There was discussion in Octave of having these even prior to @sc{Matlab}, | |
832 and the decision was made not to have these in Octave at the time for | |
6900 | 833 compatibility. The above written with sub-functions functions would be |
6612 | 834 |
835 @example | |
836 @group | |
837 function y = foo (x) | |
838 y = bar(x) | |
839 end | |
840 function y = bar (x) | |
841 y = @dots{}; | |
842 end | |
843 @end group | |
844 @end example | |
845 | |
846 Now that @sc{Matlab} has recently introduced nested functions, Octave will | |
6900 | 847 probably have them soon as well. Until then nested functions in Octave |
6612 | 848 are treated as sub-functions with the same scoping rules as |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
849 sub-functions. |
6612 | 850 |
851 The authors of Octave consider the nested function scoping rules of | |
12478
b4138a75eecc
Uniformise "Matlab" typesetting in FAQ.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11576
diff
changeset
|
852 @sc{Matlab} to be more problems than they are worth as they introduce |
6612 | 853 diffiult to find bugs as inadvertantly modifying a variable in a |
854 nested function that is also used in the parent is particularly easy. | |
855 | |
856 @item Differences in core syntax | |
857 There a few core @sc{Matlab} syntaxes that are not accepted by Octave, | |
858 these being | |
859 | |
860 @itemize @bullet | |
2866 | 861 @item |
6612 | 862 Some limitations on the use of function handles. The major difference is |
6879 | 863 related to nested function scoping rules (as above) and their use with |
6612 | 864 function handles. |
2866 | 865 |
866 @item | |
6612 | 867 Some limitations of variable argument lists on the LHS of an expression, |
868 though the most common types are accepted. | |
869 | |
2866 | 870 @item |
8128 | 871 @sc{Matlab} classdef object oriented programming is not yet supportted, |
872 though work is underway and when development more on to Octave 3.3 this | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
873 will be included in the development tree. |
6612 | 874 @end itemize |
875 | |
876 @item Differences in core functions | |
877 A large number of the @sc{Matlab} core functions (ie those that are in | |
878 the core and not a toolbox) are implemented, and certainly all of the | |
879 commonly used ones. There are a few functions that aren't implemented, | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
880 @c this is no longer true, condest is now implemented in Octave |
6879 | 881 for example @code{condest} or to do with specific missing Octave functionality |
6612 | 882 (gui, dll, java, activex, dde, web, and serial functions). Some of the |
883 core functions have limitations that aren't in the @sc{Matlab} | |
6900 | 884 version. For example the @code{sprandn} function can not force a |
6735 | 885 particular condition number for the matrix like @sc{Matlab} can. |
6612 | 886 |
887 @item Just-In-Time compiler | |
888 @sc{Matlab} includes a "Just-In-Time" compiler. This compiler allows the | |
889 acceleration of for-loops in @sc{Matlab} to almost native performance with | |
890 certain restrictions. The JIT must know the return type of all functions | |
891 called in the loops and so you can't include user functions in the loop | |
6900 | 892 of JIT optimized loops. Octave doesn't have a JIT and so to some might |
893 seem slower than @sc{Matlab}. For this reason you must vectorize your code as | |
894 much as possible. The MathWorks themselves have a good document | |
895 discussing vectorization at | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
896 @c it would be nice if we had our own guide for this instead of relying |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
897 @c on Matlab documentation. |
6612 | 898 @url{http://www.mathworks.com/support/tech-notes/1100/1109.html}. |
899 | |
900 @item Compiler | |
901 On a related point, there is no Octave compiler, and so you can't | |
902 convert your Octave code into a binary for additional speed or | |
6900 | 903 distribution. There is an example of how to do this at |
6612 | 904 @url{http://www.stud.tu-ilmenau.de/~rueckn/}, but this is a very early |
905 example code and would need lots of work to complete it. | |
906 | |
907 @item Graphic Handles | |
908 Up to Octave 2.9.9 there was no support for graphic handles in Octave | |
8128 | 909 itself. In the 3.2.N versions of Octave the support for graphics |
910 handles is converging towards full compatibility. The @code{patch} | |
911 function is currently limited to 2-D patches, due to an underlying | |
912 limitation in gnuplot. | |
6612 | 913 |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
914 @item GUI |
6900 | 915 There are no @sc{Matlab} compatible GUI functions. There are a number of |
916 bindings from Octave to Tcl/Tk, Vtk and zenity included in the | |
917 Octave Forge project (@url{http://octave.sourceforge.net}) for example | |
6612 | 918 that can be used for a GUI, but these are not @sc{Matlab} |
12478
b4138a75eecc
Uniformise "Matlab" typesetting in FAQ.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11576
diff
changeset
|
919 compatible. Work on a @sc{Matlab} compatible GUI is in an alpha stage in the |
6879 | 920 JHandles package (@url{http://octave.sourceforge.net/jhandles/index.html}). |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
921 This might be an issue if you intend to exchange Octave code with |
6879 | 922 @sc{Matlab} users. |
6612 | 923 |
924 @item Simulink | |
925 Octave itself includes no Simulink support. Typically the simulink | |
926 models lag research and are less flexible, so shouldn't really be used | |
6900 | 927 in a research environment. However, some @sc{Matlab} users that try to |
928 use Octave complain about this lack. There is a similar package to | |
929 simulink for the Octave and R projects available at | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
930 @c is this project in any state of usability? |
6900 | 931 @url{http://www.scicraft.org/} |
6612 | 932 |
933 @item Mex-Files | |
12478
b4138a75eecc
Uniformise "Matlab" typesetting in FAQ.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11576
diff
changeset
|
934 Octave includes an API to the @sc{Matlab} MEX interface. However, as MEX is |
6900 | 935 an API to the internals of @sc{Matlab} and the internals of Octave |
936 differ from @sc{Matlab}, there is necessarily a manipulation of the data | |
937 to convert from a MEX interface to the Octave equivalent. This is | |
938 notable for all complex matrices, where @sc{Matlab} stores complex | |
939 arrays as real and imaginary parts, whereas Octave respects the C99/C++ | |
940 standards of co-locating the real/imag parts in memory. Also due to the | |
941 way @sc{Matlab} allows access to the arrays passed through a pointer, | |
942 the MEX interface might require copies of arrays (even non complex | |
8128 | 943 ones). |
6612 | 944 |
945 @item Block comments | |
8128 | 946 Block comments denoted by "%@{" and "%@}" markers are supported by |
947 Octave with some limitations. The major limitation is that block | |
8292 | 948 comments are not supported within [] or @{@}. |
6612 | 949 |
950 @item Mat-File format | |
951 There are some differences in the mat v5 file format accepted by | |
952 Octave. @sc{Matlab} recently introduced the "-V7.3" save option which is | |
6900 | 953 an HDF5 format which is particularly useful for 64-bit platforms where |
12478
b4138a75eecc
Uniformise "Matlab" typesetting in FAQ.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11576
diff
changeset
|
954 the standard @sc{Matlab} format can not correctly save variables.. Octave |
6900 | 955 accepts HDF5 files, but is not yet compatible with the "-v7.3" versions |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
956 produced by @sc{Matlab}. |
6612 | 957 |
8128 | 958 Although Octave can load inline abd function handles saved by |
959 @sc{Matlab}, it can not yet save them. | |
6612 | 960 |
961 Finally, Some multi-byte unicode characters aren't yet treated in | |
962 mat-files. | |
963 | |
964 @item Profiler | |
965 Octave doesn't have a profiler. Though there is a patch for a flat | |
966 profiler, that might become a real profiler sometime in the future. see | |
967 the thread | |
968 | |
969 @url{http://www.cae.wisc.edu/pipermail/octave-maintainers/2007-January/001685.html} | |
970 | |
971 for more details | |
972 | |
973 @item Toolboxes | |
974 Octave is a community project and so the toolboxes that exist are | |
6900 | 975 donated by those interested in them through the Octave Forge website |
6612 | 976 (@url{http://octave.sourceforge.net}). These might be lacking in certain |
977 functionality relative to the @sc{Matlab} toolboxes, and might not | |
12478
b4138a75eecc
Uniformise "Matlab" typesetting in FAQ.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11576
diff
changeset
|
978 exactly duplicate the @sc{Matlab} functionality or interface. |
6612 | 979 |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
980 @c TODO: Update this to mention how it's now enabled in Octave |
6612 | 981 @item Short-circuit & and | operators |
6900 | 982 The @code{&} and @code{|} operators in @sc{Matlab} short-circuit when |
983 included in an if statemant and not otherwise. In Octave only the | |
984 @code{&&} and @code{||} short circuit. Note that this means that | |
6612 | 985 |
986 @example | |
987 @group | |
988 if (a | b) | |
989 @dots{} | |
990 end | |
991 @end group | |
992 @end example | |
993 | |
994 and | |
995 | |
996 @example | |
997 @group | |
998 t = a | b; | |
999 if t | |
1000 @dots{} | |
1001 end | |
1002 @end group | |
1003 @end example | |
1004 | |
6900 | 1005 @noindent |
6612 | 1006 are different in @sc{Matlab}. This is really a @sc{Matlab} bug, but |
1007 there is too much code out there that relies on this behavior to change | |
1008 it. Prefer the || and && operators in if statements if possible. | |
2866 | 1009 |
6612 | 1010 Note that the difference is also significant when either argument is a |
1011 function with side effects or if the first argument is a scalar and the | |
1012 second argument is an empty matrix. For example, note the difference | |
1013 between | |
1014 | |
1015 @example | |
1016 @group | |
1017 t = 1 | []; ## results in [], so... | |
1018 if (t) 1, end ## in if ([]), this is false. | |
1019 @end group | |
1020 @end example | |
1021 | |
1022 and | |
1023 | |
1024 @example | |
1025 if (1 | []) 1, end ## short circuits so condition is true. | |
1026 @end example | |
1027 | |
1028 Another case that is documented in the @sc{Matlab} manuals is that | |
1029 | |
1030 @example | |
1031 @group | |
1032 t = [1, 1] | [1, 2, 3]; ## error | |
1033 if ([1, 1] | [1, 2, 3]) 1, end ## OK | |
1034 @end group | |
1035 @end example | |
1036 | |
1037 Also @sc{Matlab} requires the operands of && and || to be scalar values but | |
1038 Octave does not (it just applies the rule that for an operand to be | |
1039 considered true, every element of the object must be nonzero or | |
1040 logically true). | |
1041 | |
1042 Finally, note the inconsistence of thinking of the condition of an if | |
1043 statement as being equivalent to @code{all(X(:))} when @var{X} is a | |
1044 matrix. This is true for all cases EXCEPT empty matrices: | |
1045 | |
1046 @example | |
1047 @group | |
1048 if ([0, 1]) == if (all ([0, 1])) ==> i.e., condition is false. | |
1049 if ([1, 1]) == if (all ([1, 1])) ==> i.e., condition is true. | |
1050 @end group | |
1051 @end example | |
1052 | |
1053 However, | |
1054 | |
1055 @example | |
1056 if ([]) != if (all ([])) | |
1057 @end example | |
1058 | |
6900 | 1059 because @code{samp ([]) == 1} (because, despite the name, it is really |
6612 | 1060 returning true if none of the elements of the matrix are zero, and since |
1061 there are no elements, well, none of them are zero). But, somewhere | |
1062 along the line, someone decided that if @code{([])} should be false. | |
1063 Mathworks probably thought it just looks wrong to have @code{[]} be true | |
1064 in this context even if you can use logical gymnastics to convince | |
1065 yourself that "all" the elements of a matrix that doesn't actually have | |
1066 any elements are nonzero. Octave however duplicates this behavior for if | |
1067 statements containing empty matrices. | |
1068 | |
8292 | 1069 @item Solvers for singular, under- and over-determined matrices |
1070 | |
12478
b4138a75eecc
Uniformise "Matlab" typesetting in FAQ.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11576
diff
changeset
|
1071 @sc{Matlab}'s solvers as used by the operators mldivide (\) and mrdivide (/), |
8292 | 1072 use a different approach than Octave's in the case of singular, under-, |
12478
b4138a75eecc
Uniformise "Matlab" typesetting in FAQ.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11576
diff
changeset
|
1073 or over-determined matrices. In the case of a singular matrix, @sc{Matlab} |
8292 | 1074 returns the result given by the LU decomposition, even though the underlying |
1075 solver has flagged the result as erroneous. Octave has made the choice | |
1076 of falling back to a minimum norm solution of matrices that have been | |
1077 flagged as singular which arguably is a better result for these cases. | |
1078 | |
1079 In the case of under- or over-determined matrices, Octave continues to | |
12478
b4138a75eecc
Uniformise "Matlab" typesetting in FAQ.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11576
diff
changeset
|
1080 use a minimum norm solution, whereas @sc{Matlab} uses an approach that is |
8292 | 1081 equivalent to |
1082 | |
1083 @example | |
1084 @group | |
1085 function x = mldivide (A, b) | |
1086 [Q, R, E] = qr(A); | |
1087 x = [A \ b, E(:, 1:m) * (R(:, 1:m) \ (Q' * b))] | |
1088 end | |
1089 @end group | |
1090 @end example | |
1091 | |
1092 @noindent | |
1093 While this approach is certainly faster and uses less memory than | |
1094 Octave's minimum norm approach, this approach seems to be inferior in | |
1095 other ways. | |
1096 | |
1097 A numerical question arises: how big can the null space component become, | |
1098 relative to the minimum-norm solution? Can it be nicely bounded, or can it be | |
1099 arbitrarily big? Consider this example: | |
1100 | |
1101 @example | |
1102 @group | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
1103 m = 10; |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
1104 n = 10000; |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
1105 A = ones(m, n) + 1e-6 * randn(m,n); |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
1106 b = ones(m, 1) + 1e-6 * randn(m,1); |
8292 | 1107 norm(A \ b) |
1108 @end group | |
1109 @end example | |
1110 | |
1111 @noindent | |
12478
b4138a75eecc
Uniformise "Matlab" typesetting in FAQ.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11576
diff
changeset
|
1112 while Octave's minimum-norm values are around 3e-2, @sc{Matlab}'s results |
8292 | 1113 are 50-times larger. For another issue, try this code: |
1114 | |
1115 @example | |
1116 @group | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
1117 m = 5; |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
1118 n = 100; |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
1119 j = floor(m * rand(1, n)) + 1; |
8292 | 1120 b = ones(m, 1); |
1121 A = zeros(m, n); | |
1122 A(sub2ind(size(A),j,1:n)) = 1; | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
1123 x = A \ b; |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
1124 [dummy,p] = sort(rand(1,n)); |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
1125 y = A(:,p)\b; |
8292 | 1126 norm(x(p)-y) |
1127 @end group | |
1128 @end example | |
1129 | |
1130 @noindent | |
12478
b4138a75eecc
Uniformise "Matlab" typesetting in FAQ.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11576
diff
changeset
|
1131 It shows that unlike in Octave, mldivide in @sc{Matlab} is not invariant |
8292 | 1132 with respect to column permutations. If there are multiple columns of |
1133 the same norm, permuting columns of the matrix gets you different | |
1134 result than permuting the solution vector. This will surprise many | |
1135 users. | |
1136 | |
12479
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
1137 Since the mldivide (\) and mrdivide (/) operators are often part of a more |
c741c1f2789e
Minor proofreading in FAQ
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12478
diff
changeset
|
1138 complex expression, where there is no room to react to warnings or flags, it |
8292 | 1139 should prefer intelligence (robustness) to speed, and so the Octave developers |
1140 are firmly of the opinion that Octave's approach for singular, under- and | |
12478
b4138a75eecc
Uniformise "Matlab" typesetting in FAQ.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11576
diff
changeset
|
1141 over-determined matrices is a better choice that @sc{Matlab}'s |
8292 | 1142 |
6612 | 1143 @item Octave extensions |
1144 The extensions in Octave over @sc{Matlab} syntax are | |
1145 very useful, but might cause issues when sharing with @sc{Matlab} users. | |
1146 A list of the major extensions that should be avoided to be compatible | |
1147 with @sc{Matlab} are | |
1148 | |
1149 @itemize @bullet | |
1150 @item | |
6900 | 1151 Comments in octave can be marked with @samp{#}. This allows POSIX |
1152 systems to have the first line as @samp{#! octave -q} and mark the script | |
6653 | 1153 itself executable. @sc{Matlab} doesn't have this feature due to the |
6900 | 1154 absence of comments starting with @samp{#}". |
2866 | 1155 |
6612 | 1156 @item |
1157 Code blocks like if, for, while, etc can be terminated with block | |
1158 specific terminations like "endif". @sc{Matlab} doesn't have this and | |
1159 all blocks must be terminated with "end" | |
1160 | |
1161 @item | |
1162 Octave has a lisp like unwind_protect block that allows blocks of | |
1163 code that terminate in an error to ensure that the variables that | |
1164 are touched are restored. You can do something similar with | |
6900 | 1165 @code{try}/@code{catch} combined with @samp{rethrow (lasterror ())} in |
1166 @sc{Matlab}, however rethrow and lasterror are only available in Octave 2.9.10 and later. | |
6612 | 1167 |
6900 | 1168 Note that using @code{try}/@code{catch} combined with @samp{rethrow |
8325
b93ac0586e4b
spelling corrections
Brian Gough<bjg@network-theory.co.uk>
parents:
8292
diff
changeset
|
1169 (lasterror ())} can not guarantee that global variables will be |
6900 | 1170 correctly reset, as it won't catch user interrupts with Ctrl-C. For |
1171 example | |
6612 | 1172 |
1173 @example | |
1174 @group | |
1175 global a | |
1176 a = 1; | |
1177 try | |
1178 _a = a; | |
1179 a = 2 | |
1180 while true | |
1181 end | |
1182 catch | |
1183 fprintf ('caught interrupt\n'); | |
1184 a = _a; | |
1185 rethrow (lasterror()); | |
1186 end | |
1187 @end group | |
1188 @end example | |
1189 | |
1190 @noindent | |
1191 compared to | |
1192 | |
1193 @example | |
1194 @group | |
1195 global a | |
1196 a = 1; | |
1197 unwind_protect | |
1198 _a = a; | |
1199 a = 2 | |
1200 while true | |
1201 end | |
1202 unwind_protect_cleanup | |
1203 fprintf ('caught interrupt\n'); | |
1204 a = _a; | |
1205 end | |
1206 @end group | |
1207 @end example | |
1208 | |
1209 Typing Ctrl-C in the first case returns the user directly to the | |
6879 | 1210 prompt, and the variable "a" is not reset to the saved value. In the |
6900 | 1211 second case the variable "a" is reset correctly. Therefore @sc{Matlab} |
6612 | 1212 gives no save way of temporarily changing global variables. |
1213 | |
1214 @item | |
1215 Indexing can be applied to all objects in Octave and not just | |
1216 variable. Therefore @code{sin(x)(1:10);} for example is perfectly valid | |
1217 in Octave but not @sc{Matlab}. To do the same in @sc{Matlab} you must do | |
1218 @code{y = sin(x); y = y([1:10]);} | |
1219 | |
1220 @item | |
6900 | 1221 Octave has the operators "++", "--", "-=", "+=", "*=", etc. As |
6612 | 1222 @sc{Matlab} doesn't, if you are sharing code these should be avoided. |
1223 | |
1224 @item | |
6900 | 1225 Character strings in Octave can be denoted with double or single |
1226 quotes. There is a subtle difference between the two in that escaped | |
1227 characters like @code{\n} (newline), @code{\t} (tab), etc are | |
1228 interpreted in double quoted strings but not single quoted strings. This | |
1229 difference is important on Windows platforms where the "\" character is | |
1230 used in path names, and so single quoted strings should be used in | |
1231 paths. @sc{Matlab} doesn't have double quoted strings and so they should | |
1232 be avoided if the code will be transfered to a @sc{Matlab} user. | |
6612 | 1233 @end itemize |
1234 | |
1235 @end itemize | |
2866 | 1236 |
4830 | 1237 @node Index |
2866 | 1238 @appendix Concept Index |
1239 | |
1240 @printindex cp | |
1241 | |
1242 @page | |
1243 @contents | |
1244 @bye |