Mercurial > octave
annotate scripts/general/pol2cart.m @ 28789:28de41192f3c
Eliminate unneeded verification of nargin, nargout in m-files.
* FIRfilter.m, FIRfilter_aggregation.m, get.m, polynomial.m,
polynomial_superiorto.m, polynomial2.m, makeUniqueStrings.m, base64decode.m,
base64encode.m, cd.m, lin2mu.m, record.m, sound.m, soundsc.m, accumarray.m,
accumdim.m, bitcmp.m, bitset.m, cart2pol.m, celldisp.m, circshift.m,
cplxpair.m, cumtrapz.m, flip.m, idivide.m, interpft.m, logspace.m, pol2cart.m,
polyarea.m, postpad.m, prepad.m, rat.m, rot90.m, rotdim.m, shift.m, shiftdim.m,
sortrows.m, trapz.m, dsearch.m, dsearchn.m, getappdata.m, getpixelposition.m,
guidata.m, guihandles.m, isappdata.m, listfonts.m, uigetdir.m,
waitforbuttonpress.m, __makeinfo__.m, doc.m, get_first_help_sentence.m,
autumn.m, bone.m, brighten.m, cmpermute.m, cmunique.m, colorcube.m, contrast.m,
cool.m, copper.m, cubehelix.m, flag.m, gray.m, gray2ind.m, hot.m, hsv.m,
im2double.m, im2frame.m, imformats.m, jet.m, lines.m, ocean.m, pink.m, prism.m,
rainbow.m, rgbplot.m, spinmap.m, spring.m, summer.m, viridis.m, white.m,
winter.m, beep.m, importdata.m, is_valid_file_id.m, javachk.m, javaclasspath.m,
findstr.m, genvarname.m, strmatch.m, bandwidth.m, commutation_matrix.m, cond.m,
cross.m, isdefinite.m, ishermitian.m, issymmetric.m, krylov.m, linsolve.m,
logm.m, lscov.m, null.m, ordeig.m, orth.m, rank.m, rref.m, vecnorm.m,
bunzip2.m, citation.m, computer.m, copyfile.m, dir.m, dos.m, fileattrib.m,
gunzip.m, inputParser.m, inputname.m, ismac.m, ispc.m, isunix.m, license.m,
list_primes.m, methods.m, mkdir.m, movefile.m, nargchk.m, news.m,
orderfields.m, recycle.m, tar.m, unix.m, unpack.m, untar.m, unzip.m, ver.m,
version.m, what.m, zip.m, decic.m, fminbnd.m, fminunc.m, fsolve.m, fzero.m,
glpk.m, humps.m, lsqnonneg.m, optimget.m, pqpnonneg.m, sqp.m, pathdef.m,
camlookat.m, hidden.m, specular.m, plotmatrix.m, smooth3.m, sombrero.m,
stemleaf.m, __gnuplot_drawnow__.m, __opengl_info__.m, ancestor.m, cla.m,
close.m, closereq.m, copyobj.m, gca.m, gcf.m, ginput.m, graphics_toolkit.m,
groot.m, hgload.m, hgsave.m, isgraphics.m, ishold.m, linkaxes.m, meshgrid.m,
newplot.m, refresh.m, refreshdata.m, rotate.m, saveas.m, struct2hdl.m, conv.m,
mkpp.m, mpoles.m, padecoef.m, pchip.m, polyder.m, polyfit.m, polygcd.m,
polyint.m, polyout.m, polyval.m, ppder.m, ppint.m, getpref.m, ispref.m,
rmpref.m, profexport.m, profshow.m, powerset.m, arch_fit.m, arma_rnd.m,
blackman.m, detrend.m, diffpara.m, fftconv.m, fftfilt.m, filter2.m, freqz.m,
freqz_plot.m, hamming.m, hanning.m, sinetone.m, sinewave.m, spectral_adf.m,
spectral_xdf.m, stft.m, unwrap.m, gplot.m, ichol.m, ilu.m, spdiags.m, sprand.m,
sprandn.m, spstats.m, svds.m, treelayout.m, treeplot.m, betainc.m,
betaincinv.m, ellipke.m, gammainc.m, gammaincinv.m, legendre.m, pow2.m,
hankel.m, pascal.m, rosser.m, toeplitz.m, bounds.m, corr.m, cov.m, histc.m,
kendall.m, kurtosis.m, mad.m, mode.m, moment.m, prctile.m, quantile.m, range.m,
ranks.m, run_count.m, skewness.m, spearman.m, std.m, var.m, zscore.m,
dec2base.m, dec2bin.m, dec2hex.m, index.m, mat2str.m, native2unicode.m,
ostrsplit.m, strjoin.m, strjust.m, strtok.m, substr.m, unicode2native.m,
untabify.m, __debug_octave__.m, demo.m, example.m, fail.m, oruntests.m,
dump_demos.m, speed.m, test.m, date.m, datenum.m, datestr.m, datevec.m,
is_leap_year.m, now.m, weekday.m:
Eliminate unneeded verification of nargin, nargout in m-files now that
the interpreter checks these values.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 24 Sep 2020 14:44:58 -0700 |
parents | e82484e1b2f6 |
children | 90fea9cc9caa |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
3 ## Copyright (C) 2000-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
3803 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
3803 | 11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22432
diff
changeset
|
13 ## (at your option) any later version. |
3803 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22432
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22432
diff
changeset
|
18 ## GNU General Public License for more details. |
3803 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
3803 | 25 |
26 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
27 ## @deftypefn {} {[@var{x}, @var{y}] =} pol2cart (@var{theta}, @var{r}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
28 ## @deftypefnx {} {[@var{x}, @var{y}, @var{z}] =} pol2cart (@var{theta}, @var{r}, @var{z}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
29 ## @deftypefnx {} {[@var{x}, @var{y}] =} pol2cart (@var{P}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
30 ## @deftypefnx {} {[@var{x}, @var{y}, @var{z}] =} pol2cart (@var{P}) |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
31 ## Transform polar or cylindrical coordinates to Cartesian coordinates. |
10688
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
9168
diff
changeset
|
32 ## |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
33 ## The inputs @var{theta}, @var{r}, (and @var{z}) must be the same shape, or |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
34 ## scalar. If called with a single matrix argument then each row of @var{P} |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
35 ## represents the polar coordinate pair (@var{theta}, @var{r}) or the |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
36 ## cylindrical triplet (@var{theta}, @var{r}, @var{z}). |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
37 ## |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
38 ## The outputs @var{x}, @var{y} (, and @var{z}) match the shape of the inputs. |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
39 ## For a matrix input @var{P} the outputs will be column vectors with rows |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
40 ## corresponding to the rows of the input matrix. |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
41 ## |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
42 ## @var{theta} describes the angle relative to the positive x-axis measured in |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
43 ## the xy-plane. |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
44 ## |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
45 ## @var{r} is the distance to the z-axis @w{(0, 0, z)}. |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
46 ## |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
47 ## @var{z}, if present, is unchanged by the transformation. |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
48 ## |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
49 ## The coordinate transformation is computed using: |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
50 ## |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
51 ## @tex |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
52 ## $$ x = r \cos \theta $$ |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
53 ## $$ y = r \sin \theta $$ |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
54 ## $$ z = z $$ |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
55 ## @end tex |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
56 ## @ifnottex |
10688
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
9168
diff
changeset
|
57 ## |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
58 ## @example |
28753 | 59 ## @group |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
60 ## @var{x} = @var{r} * cos (@var{theta}) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
61 ## @var{y} = @var{r} * sin (@var{theta}) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
62 ## @var{z} = @var{z} |
28753 | 63 ## @end group |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
64 ## @end example |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
65 ## |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
66 ## @end ifnottex |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
67 ## @c FIXME: Remove this note in Octave 9.1 (two releases after 7.1). |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
68 ## Note: For @sc{matlab} compatibility, this function no longer returns a full |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
69 ## coordinate matrix when called with a single return argument. |
10688
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
9168
diff
changeset
|
70 ## @seealso{cart2pol, sph2cart, cart2sph} |
3803 | 71 ## @end deftypefn |
72 | |
17584
6278085742b7
pol2cart.m: Fix bug with z-input and only 1 output (bug #40184)
Rik <rik@octave.org>
parents:
16968
diff
changeset
|
73 function [x, y, z] = pol2cart (theta, r, z = []) |
3803 | 74 |
28789
28de41192f3c
Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents:
28753
diff
changeset
|
75 if (nargin < 1) |
10688
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
9168
diff
changeset
|
76 print_usage (); |
3803 | 77 endif |
78 | |
10688
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
9168
diff
changeset
|
79 if (nargin == 1) |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
80 if (! (isnumeric (theta) && ismatrix (theta))) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
81 error ("cart2pol: matrix input P must be 2-D numeric array"); |
10688
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
9168
diff
changeset
|
82 endif |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
83 if (isvector (theta)) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
84 n = numel (theta); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
85 if (n != 2 && n != 3) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
86 error ("cart2pol: matrix input must be a 2- or 3-element vector or a 2- or 3-column array"); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
87 endif |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
88 if (n == 3) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
89 z = theta(3); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
90 endif |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
91 r = theta(2); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
92 theta = theta(1); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
93 |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
94 else |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
95 ncols = columns(theta); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
96 if (ncols != 2 && ncols != 3) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
97 error ("cart2pol: matrix input must be a 2- or 3-element vector or a 2- or 3-column array"); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
98 endif |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
99 |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
100 if (ncols == 3) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
101 z = theta(:,3); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
102 endif |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
103 r = theta(:,2); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
104 theta = theta(:,1); |
21172
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
105 endif |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
106 |
10688
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
9168
diff
changeset
|
107 elseif (nargin == 2) |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
108 if (! (isnumeric (theta) && isnumeric (r))) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
109 error ("pol2cart: THETA, R must be numeric arrays or scalars"); |
22432
1e88747417e6
Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents:
21178
diff
changeset
|
110 endif |
1e88747417e6
Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents:
21178
diff
changeset
|
111 [err, theta, r] = common_size (theta, r); |
1e88747417e6
Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents:
21178
diff
changeset
|
112 if (err) |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
113 error ("pol2cart: THETA, R must be the same size or scalars"); |
10688
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
9168
diff
changeset
|
114 endif |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
115 |
10688
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
9168
diff
changeset
|
116 elseif (nargin == 3) |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
117 if (! (isnumeric (theta) && isnumeric (r) && isnumeric (z))) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
118 error ("pol2cart: THETA, R, Z must be numeric arrays or scalars"); |
22432
1e88747417e6
Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents:
21178
diff
changeset
|
119 endif |
1e88747417e6
Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents:
21178
diff
changeset
|
120 [err, theta, r, z] = common_size (theta, r, z); |
1e88747417e6
Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents:
21178
diff
changeset
|
121 if (err) |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
122 error ("pol2cart: THETA, R, Z must be the same size or scalars"); |
10688
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
9168
diff
changeset
|
123 endif |
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
9168
diff
changeset
|
124 endif |
8533
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
125 |
10688
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
9168
diff
changeset
|
126 x = r .* cos (theta); |
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
9168
diff
changeset
|
127 y = r .* sin (theta); |
8533
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
128 |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
129 endfunction |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
130 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
131 |
8533
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
132 %!test |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
133 %! t = [0, 0.5, 1] * pi; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
134 %! r = 1; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
135 %! [x, y] = pol2cart (t, r); |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
136 %! assert (x, [1, 0, -1], eps); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
137 %! assert (y, [0, 1, 0], eps); |
8533
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
138 |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
139 %!test |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
140 %! t = [0, 1, 1] * pi/4; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
141 %! r = sqrt (2) * [0, 1, 2]; |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
142 %! [x, y] = pol2cart (t, r); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
143 %! assert (x, [0, 1, 2], 2*eps); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
144 %! assert (y, [0, 1, 2], 2*eps); |
8533
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
145 |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
146 %!test |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
147 %! t = [0, 1, 1] * pi/4; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
148 %! r = sqrt (2) * [0, 1, 2]; |
8533
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
149 %! z = [0, 1, 2]; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
150 %! [x, y, z2] = pol2cart (t, r, z); |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
151 %! assert (x, [0, 1, 2], 2*eps); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
152 %! assert (y, [0, 1, 2], 2*eps); |
22432
1e88747417e6
Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents:
21178
diff
changeset
|
153 %! assert (z2, z); |
3803 | 154 |
8533
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
155 %!test |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
156 %! t = [0; 1; 1] * pi/4; |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
157 %! r = sqrt (2) * [0; 1; 2]; |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
158 %! z = [0; 1; 2]; |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
159 %! [x, y, z2] = pol2cart (t, r, z); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
160 %! assert (x, [0; 1; 2], 2*eps); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
161 %! assert (y, [0; 1; 2], 2*eps); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
162 %! assert (z2, z); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
163 |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
164 |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
165 %!test |
8533
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
166 %! t = 0; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
167 %! r = [0, 1, 2]; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
168 %! z = [0, 1, 2]; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
169 %! [x, y, z2] = pol2cart (t, r, z); |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
170 %! assert (x, [0, 1, 2], eps); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
171 %! assert (y, [0, 0, 0], eps); |
22432
1e88747417e6
Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents:
21178
diff
changeset
|
172 %! assert (z2, z); |
8533
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
173 |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
174 %!test |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
175 %! t = [1, 1, 1]*pi/4; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
176 %! r = 1; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
177 %! z = [0, 1, 2]; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
178 %! [x, y, z2] = pol2cart (t, r, z); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
179 %! assert (x, [1, 1, 1] / sqrt (2), eps); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
180 %! assert (y, [1, 1, 1] / sqrt (2), eps); |
22432
1e88747417e6
Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents:
21178
diff
changeset
|
181 %! assert (z2, z); |
8533
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
182 |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
183 %!test |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
184 %! t = 0; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
185 %! r = [1, 2, 3]; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
186 %! z = 1; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
187 %! [x, y, z2] = pol2cart (t, r, z); |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
188 %! assert (x, [1, 2, 3], eps); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
189 %! assert (y, [0, 0, 0] / sqrt (2), eps); |
22432
1e88747417e6
Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents:
21178
diff
changeset
|
190 %! assert (z2, [1, 1, 1]); |
8533
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
8507
diff
changeset
|
191 |
10688
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
9168
diff
changeset
|
192 %!test |
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
9168
diff
changeset
|
193 %! P = [0, 0; pi/4, sqrt(2); pi/4, 2*sqrt(2)]; |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
194 %! [x, y] = pol2cart(P); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
195 %! assert (x, [0; 1; 2], 2*eps); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
196 %! assert (y, [0; 1; 2], 2*eps); |
10688
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
9168
diff
changeset
|
197 |
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
9168
diff
changeset
|
198 %!test |
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
9168
diff
changeset
|
199 %! P = [0, 0, 0; pi/4, sqrt(2), 1; pi/4, 2*sqrt(2), 2]; |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
200 %! [x, y, z] = pol2cart(P); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
201 %! assert (x, [0; 1; 2], 2*eps); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
202 %! assert (y, [0; 1; 2], 2*eps); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
203 %! assert (z, P(:,3), 2*eps); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
204 |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
205 %!test |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
206 %! P = [0, 0, 0; pi/4, sqrt(2), 1; pi/4, 2*sqrt(2), 2; 0, 0, 0]; |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
207 %! [x, y, z] = pol2cart(P); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
208 %! assert (x, [0; 1; 2; 0], 2*eps); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
209 %! assert (y, [0; 1; 2; 0], 2*eps); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
210 %! assert (z, P(:,3), 2*eps); |
10688
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
9168
diff
changeset
|
211 |
21172
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
212 %!test |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
213 %! r = ones (1, 1, 1, 2); |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
214 %! r(1, 1, 1, 2) = 2; |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
215 %! t = pi/2 * r; |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
216 %! [x, y] = pol2cart (t, r); |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
217 %! X = zeros (1, 1, 1, 2); |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
218 %! X(1, 1, 1, 2) = -2; |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
219 %! Y = zeros (1, 1, 1, 2); |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
220 %! Y(1, 1, 1, 1) = 1; |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
221 %! assert (x, X, 2*eps); |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
222 %! assert (y, Y, 2*eps); |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
223 |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
224 %!test |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
225 %! [t, r, Z] = meshgrid ([0, pi/2], [1, 2], [0, 1]); |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
226 %! [x, y, z] = pol2cart (t, r, Z); |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
227 %! X = zeros(2, 2, 2); |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
228 %! X(:, 1, 1) = [1; 2]; |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
229 %! X(:, 1, 2) = [1; 2]; |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
230 %! Y = zeros(2, 2, 2); |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
231 %! Y(:, 2, 1) = [1; 2]; |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
232 %! Y(:, 2, 2) = [1; 2]; |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
233 %! assert (x, X, eps); |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
234 %! assert (y, Y, eps); |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
235 %! assert (z, Z); |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
236 |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
237 ## Test input validation |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
238 %!error pol2cart () |
5f62b5dae8b1
Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents:
20158
diff
changeset
|
239 %!error pol2cart (1,2,3,4) |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
240 %!error <matrix input P must be 2-D numeric array> pol2cart ({1,2,3}) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
241 %!error <matrix input P must be 2-D numeric array> pol2cart (ones (3,3,2)) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
242 %!error <matrix input must be a 2- or 3-element> pol2cart ([1]) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
243 %!error <matrix input must be a 2- or 3-element> pol2cart ([1,2,3,4]) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
244 %!error <must be numeric arrays or scalars> pol2cart ({1,2,3}, [1,2,3]) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
245 %!error <must be numeric arrays or scalars> pol2cart ([1,2,3], {1,2,3}) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
246 %!error <must be the same size or scalars> pol2cart (ones (3,3,3), ones (3,2,3)) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
247 %!error <must be the same size or scalars> pol2cart ([1; 1], [2, 2]) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
248 %!error <must be the same size or scalars> pol2cart ([1; 1], [2, 2], [3, 3]) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
249 %!error <must be numeric arrays or scalars> pol2cart ({1,2,3}, [1,2,3], [1,2,3]) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
250 %!error <must be numeric arrays or scalars> pol2cart ([1,2,3], {1,2,3}, [1,2,3]) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
251 %!error <must be numeric arrays or scalars> pol2cart ([1,2,3], [1,2,3], {1,2,3}) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
252 %!error <must be the same size or scalars> pol2cart (ones (3,3,3), 1, ones (3,2,3)) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
253 %!error <must be the same size or scalars> pol2cart (ones (3,3,3), ones (3,2,3), 1) |