[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Histc under octave
From: |
lucas21 |
Subject: |
Histc under octave |
Date: |
Wed, 26 Apr 2017 05:42:42 -0700 (PDT) |
Hi everybody,
I recently start (since this morning) to work with Octave. I use to operate
with Matlab.
Anyway, I try to use my matlab code under Octave, there was a few
modifications to make, which I did, but I cant figure out the last one.
Here is the message that I have when I try to execute my code:
parse error near line 49 of file
C:\Octave\OCTAVE~1.1\share\octave\4.2.1\m\statistics\base\histc.m
syntax error
>>> if(nargin < 2 || nargin > 3)
^
error: called from
mc3dBASF_GW2 at line 553 column 19
MC_fluo_Main3d_BASF_GW_zemax_base_de_travail at line 301 column 194
mc3dBASF_GW2 at line 553 column 19
MC_fluo_Main3d_BASF_GW_zemax_base_de_travail at line 301 column 194
mc3dBASF_GW2 at line 9 column 7
stopped in C:\Users\LZ419B9N\Desktop\Code_Lucas\mc3dBASF_GW2.m at line 553
553: MPV(lambdaIdx0un) = histc(lambdaIdx0,lambdaIdx0un);
I tried to look to make some modification to this file "histc" but nothing
worked...
Here is the histc file:
function N = histc (X, EDGES)
N = histc (X, EDGES, DIM)
[N, IDX] = histc (...)
if(nargin < 2 || nargin > 3)
print_usage ();
endif
if (! isreal (x))
error ("histc: X argument must be real-valued, not complex");
endif
num_edges = numel (edges);
if (num_edges == 0)
error ("histc: EDGES must not be empty");
endif
if (! isreal (edges))
error ("histc: EDGES must be real-valued, not complex");
else
## Make sure 'edges' is sorted
edges = edges(:);
if (! issorted (edges) || edges(1) > edges(end))
warning ("histc: edge values not sorted on input");
edges = sort (edges);
endif
endif
nd = ndims (x);
sz = size (x);
if (nargin < 3)
## Find the first non-singleton dimension.
(dim = find (sz > 1, 1)) || (dim = 1);
else
if (!(isscalar (dim) && dim == fix (dim))
|| !(1 <= dim && dim <= nd))
error ("histc: DIM must be an integer and a valid dimension");
endif
endif
nsz = sz;
nsz(dim) = num_edges;
## the splitting point is 3 bins
if (num_edges <= 3)
## This is the O(M*N) algorithm.
## Allocate the histogram
n = zeros (nsz);
## Allocate 'idx'
if (nargout > 1)
idx = zeros (sz);
endif
## Prepare indices
idx1 = cell (1, dim-1);
for k = 1:length (idx1)
idx1{k} = 1:sz(k);
endfor
idx2 = cell (length (sz) - dim);
for k = 1:length (idx2)
idx2{k} = 1:sz(k+dim);
endfor
## Compute the histograms
for k = 1:num_edges-1
b = (edges(k) <= x & x < edges(k+1));
n(idx1{:}, k, idx2{:}) = sum (b, dim);
if (nargout > 1)
idx(b) = k;
endif
endfor
b = (x == edges(end));
n(idx1{:}, num_edges, idx2{:}) = sum (b, dim);
if (nargout > 1)
idx(b) = num_edges;
endif
else
## This is the O(M*log(N) + N) algorithm.
## Look-up indices.
idx = lookup (edges, x);
## Zero invalid ones (including NaNs). x < edges(1) are already zero.
idx(! (x <= edges(end))) = 0;
iidx = idx;
## In case of matrix input, we adjust the indices.
if (! isvector (x))
nl = prod (sz(1:dim-1));
nn = sz(dim);
nu = prod (sz(dim+1:end));
if (nl != 1)
iidx = (iidx-1) * nl;
iidx += reshape (kron (ones (1, nn*nu), 1:nl), sz);
endif
if (nu != 1)
ne =length (edges);
iidx += reshape (kron (nl*ne*(0:nu-1), ones (1, nl*nn)), sz);
endif
endif
## Select valid elements.
iidx = iidx(idx != 0);
## Call accumarray to sum the indexed elements.
n = accumarray (iidx(:), 1, nsz);
endif
endfunction
%!test
%! x = linspace (0, 10, 1001);
%! n = histc (x, 0:10);
%! assert (n, [repmat(100, 1, 10), 1]);
%!test
%! x = repmat (linspace (0, 10, 1001), [2, 1, 3]);
%! n = histc (x, 0:10, 2);
%! assert (n, repmat ([repmat(100, 1, 10), 1], [2, 1, 3]));
%!error histc ()
%!error histc (1)
%!error histc (1, 2, 3, 4)
%!error histc ([1:10 1+i], 2)
%!error histc (1:10, [])
%!error histc (1, 1, 3)
Thanks in advance,
Lucas
--
View this message in context:
http://octave.1599824.n4.nabble.com/Histc-under-octave-tp4683039.html
Sent from the Octave - General mailing list archive at Nabble.com.
- Histc under octave,
lucas21 <=
- Re: Histc under octave, Mike Miller, 2017/04/26
- Re: Histc under octave, Mike Miller, 2017/04/27
- Re: Histc under octave, lucas21, 2017/04/28
- Message not available
- Message not available
- Re: Histc under octave, Nicholas Jankowski, 2017/04/28
- Re: Histc under octave, lucas21, 2017/04/28