-
-
Save AALEKH/22767c80ae2015a9c17d60edf792a70f to your computer and use it in GitHub Desktop.
One Hot Encoder/Decoder in Octave/Matlab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mat = label2mat(label, size) | |
if ~exist('size', 'var') || isempty(size) | |
size = 10; | |
end | |
if label > size | |
error('Label (%d) should be < size (%d).', label, size); | |
end | |
I = eye(size); | |
mat = I(:, label); | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function label = mat2label(mat) | |
size = length(mat); | |
for i = 1:size | |
if mat(i) == 1 | |
label = i; | |
break; | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment