Skip to content

Add categorical vector support to randsample #342

@SergeantQuickscoper

Description

@SergeantQuickscoper

Currently, randsample.m requires categorical vector support for input population argument to be MATLAB compatible, as observed in the docs. This issue proposes adding support and necessary tests to randsample.m as part of the ongoing datatypes integration effort.

Current categorical input seems to have this behavior:

octave:24> C = categorical({'red','blue','green','red','blue','green'});
octave:25> C
C =
  1x6 categorical array

    red    blue    green    red    blue    green    

octave:26> y = randsample(C, 1)
y =
  categorical

   red
octave:27> y = randsample(C, 2)
error: randsample: The input k must be a non-negativeinteger. Sampling without replacement needs k <= n.
error: called from
    randsample at line 54 column 5

where any k > 1 will raise an error.

Note: string support seems to already be in place, but I did not test extensively. Could also look at that while tackling this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions