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 realvalued, 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 realvalued, 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 nonsingleton 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, dim1); 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_edges1 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. ## Lookup 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:dim1)); nn = sz(dim); nu = prod (sz(dim+1:end)); if (nl != 1) iidx = (iidx1) * nl; iidx += reshape (kron (ones (1, nn*nu), 1:nl), sz); endif if (nu != 1) ne =length (edges); iidx += reshape (kron (nl*ne*(0:nu1), 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 
On Wed, Apr 26, 2017 at 05:42:42 0700, lucas21 wrote:
> 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) > ^ If I modify histc.m to look like what you have here: > Here is the histc file: > > function N = histc (X, EDGES) > N = histc (X, EDGES, DIM) > [N, IDX] = histc (...) then I get the same error. Why did you change the contents of histc.m? You should probably restore the original function file or reinstall Octave if you have to. If you are just learning how to use Octave, it's best not to edit and make changes to function files provided with the software.  mike _______________________________________________ Helpoctave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/helpoctave 
This post was updated on .
Thanks for the answer.
I try to run the file histc.m by itself and it told me to change the content of the program. That's why I changed it. Here is the error that I got with the original file: error: histc: EDGES must not be empty error: called from histc at line 57 column 5 mc3dBASF_GW2 at line 578 column 26 MC_fluo_Main3d_BASF_GW_zemax_base_de_travail at line 301 column 194 histc at line 57 column 5 mc3dBASF_GW2 at line 578 column 26 MC_fluo_Main3d_BASF_GW_zemax_base_de_travail at line 301 column 194 mc3dBASF_GW2 at line 9 column 7 stopped in C:\Octave\OCTAVE~1.1\share\octave\4.2.1\m\statistics\base\histc.m at line 57 57: error ("histc: EDGES must not be empty"); I dont really understand the "EDGES must not be empty". Am I using it wrong? Here is the line that use this fonction: lambdaIdx0 = lambdaIdx(photons(:,2) == 3); lambdaIdx0un = unique(lambdaIdx0); MP2(lambdaIdx0un) = histc(lambdaIdx0,lambdaIdx0un); Thanks again 
" it told me to change the content" What exactly told you to edit histc.m directly? _______________________________________________ Helpoctave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/helpoctave 
When I execute the file histc.m I have this message:
error: Invalid call to histc. Correct usage is:  N = histc (X, EDGES)  N = histc (X, EDGES, DIM)  [N, IDX] = histc (...) But I think it was silly to just run this file. I am new in the computer programming. 
error: Invalid call to histc. Correct usage is: That message means you did not properly try to use histc, not that you necessarily should change histc. It is showing you examples of proper usage. _______________________________________________ Helpoctave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/helpoctave 
In reply to this post by lucas21
On Thu, Apr 27, 2017 at 00:12:46 0700, lucas21 wrote:
> Here is the error that I got with the original file: > > error: histc: EDGES must not be empty > error: called from > histc at line 57 column 5 > mc3dBASF_GW2 at line 578 column 26 > MC_fluo_Main3d_BASF_GW_zemax_base_de_travail at line 301 column 194 > histc at line 57 column 5 > mc3dBASF_GW2 at line 578 column 26 > MC_fluo_Main3d_BASF_GW_zemax_base_de_travail at line 301 column 194 > mc3dBASF_GW2 at line 9 column 7 > stopped in C:\Octave\OCTAVE~1.1\share\octave\4.2.1\m\statistics\base\histc.m > at line 57 > 57: error ("histc: EDGES must not be empty"); > > > I dont really understand the "EDGES" must not be empty". Am I using it > wrong? > Here is the line that use this fonction: > > lambdaIdx0 = lambdaIdx(photons(:,2) == 3); > lambdaIdx0un = unique(lambdaIdx0); > MP2(lambdaIdx0un) = histc(lambdaIdx0,lambdaIdx0un); The error message is saying that the second argument is empty. Maybe no values of photons are exactly equal to 3?  mike _______________________________________________ Helpoctave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/helpoctave 
I don't think so because there is other lines with other values for EDGES. And the file runs perfectly with Matlab.

Can you provide a small data set and a test script that causes this error? A Matlab incompatibility is a significant concern and it would be useful for one of us to be able to reproduce what you see and try to step through and find the error. Nick J. _______________________________________________ Helpoctave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/helpoctave 
Sorry, I did not quite understand what is it that you want. I am not a computer programmer so I am not really familiar with the english vocab.

Indeed there is incompatibility between Matlab and Octave when EDGES is empty,
See bug 49944 [1]. This bug was fixed in the development branch of Octave, and will be available in the next major release of Octave. You can see the fix in [2]. If you want to fix it your self, you can edit histc.m, and replace the line: error ("histc: EDGES must not be empty"); with the lines: warning ("histc: empty EDGES specified\n"); n = idx = []; return; Good luck, Avinoam [1] [https://savannah.gnu.org/bugs/?49944] [2] [http://hg.savannah.gnu.org/hgweb/octave/rev/af64b6b61db9] 
Free forum by Nabble  Edit this page 