From bug-octave-request at bevo dot che dot wisc dot edu Tue Nov 18 12:29:43 2003 Subject: [patch] make statistics/base/iqr.m work with matrices From: "John W. Eaton" To: Danilo Piazzalunga Cc: bug-octave at bevo dot che dot wisc dot edu Date: Tue, 18 Nov 2003 12:29:40 -0600 On 16-Nov-2003, Danilo Piazzalunga wrote: | Bug report for Octave 2.1.50 configured for i386-pc-linux-gnu | | Description: | ----------- | |     The `iqr' function gives an error when its argument is a matrix, while |     in documentation it is stated that it should compute the IQR for each |     column. | | Repeat-By: | --------- | |     octave:1> a=randn(10,6); |     octave:2> iqr(a) |     error: empirical_inv: data must be a vector | | Fix: | --- | | This patch solves the problem. It was tested succesfully with scalars,row and | column vectors, matrices (only real values -- complex values not tested). | Empty matrices were not considered. | | | --- octave/scripts/statistics/base/iqr.m        2003-11-05 04:06:15.000000000 | +0100 | +++ octave/scripts/statistics/base/iqr.m.new    2003-11-16 13:44:03.000000000 | +0100 | at @ -34,6 +34,15 @@ |      usage ("iqr (x)"); |    endif |   | -  y = empirical_inv (3/4, x) - empirical_inv (1/4, x); | +  if (rows (x) == 1) | +    x = x.'; | +  endif | + | +  [r, c] = size(x); | +  y = zeros(1, c); | + | +  for i = (1:c); | +    y(i) = empirical_inv (3/4, x(:,i)) - empirical_inv (1/4, x(:,i)); | +  endfor |   |  endfunction I applied this patch, but it might be a better solution to have empirical_inv handle matrix args. jwe ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------