Skip to content

Conversation

@AvanishSalunke
Copy link
Contributor

closes #364

@AvanishSalunke AvanishSalunke changed the title Allowing normrnd it to return empty matrix. Allow normrnd it to return empty matrix. Jan 23, 2026
@AvanishSalunke AvanishSalunke changed the title Allow normrnd it to return empty matrix. Allow normrnd to return empty matrix. Jan 23, 2026
@pr0m1th3as
Copy link
Member

pr0m1th3as commented Jan 23, 2026

Your fix is is not covering for

>> normrnd (0,1,[1,0,1])
ans = [](1x0)
>> normrnd (0,1,[5,0,1])
ans = [](5x0)
>> normrnd (0,1,[5,0,2, 1])
ans = [](5x0x2)

The if (isempty) statement is a good start, but assigning [] for every case will not cut it

@pr0m1th3as
Copy link
Member

BTW, is this behavior only limited to normrnd in MATLAB? I doubt this, but you should check first. If this affects all *rnd distribution functions, then whatever fix we come up for normrnd should be applied to all other rnd functions.

@AvanishSalunke
Copy link
Contributor Author

BTW, is this behavior only limited to normrnd in MATLAB? I doubt this, but you should check first. If this affects all *rnd distribution functions, then whatever fix we come up for normrnd should be applied to all other rnd functions.

that was exactly what i was thinking of, this minute check might be missing with other rnd functions as well, if yes we can fix it.
Thanks !!

@AvanishSalunke
Copy link
Contributor Author

@pr0m1th3as
Matlab also returns the same :

>> normrnd (0,1,[1,0,1])

ans =

  1×0 empty double row vector

>> normrnd (0,1,[5,0,1])

ans =

  5×0 empty double matrix

>> normrnd (0,1,[5,0,2, 1])

ans =

  5×0×2 empty double array

also the else conditions cover it perfectly :

    if (isempty (varargin{1}))
        sz = [0, 0];
    elseif (isscalar (varargin{1}) && varargin{1} >= 0 ...
                               && varargin{1} == fix (varargin{1}))
      sz = [varargin{1}, varargin{1}];
    elseif (isrow (varargin{1}) && all (varargin{1} >= 0) ...
                                && all (varargin{1} == fix (varargin{1})))
      sz = varargin{1};
    else
      error (strcat ("normrnd: SZ must be a scalar or a row vector", ...
                     " of non-negative integers."));
    endif

I also checked another function ncx2rnd it also does the same, so fixes for *rnd functios would be needed

@AvanishSalunke AvanishSalunke deleted the normrnd branch January 24, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

normrnd.m does not return empty matrix.

2 participants