I have a matrix of dummy variables, where each row is all 0 except for a single 1 indicating which class that sample is a member of. For example [1 0 0; 0 0 1] indicates that the first sample is from class 1 and the second from class 3. I want a function that returns [1; 3].
The function dummyvar is the inverse of what I want. Is there an elegant solution that doesn’t require a for loop?
You can use the
findcommand.EDIT: In order to keep the proper order of more complex dummies, we have to get the row index of the transpose, instead of the more intuitive column index of the array. Thanks to @woodchips for spotting this!