Created
December 26, 2016 23:18
-
-
Save hunan-rostomyan/410b902c2faf9eb302c5266902a4ed24 to your computer and use it in GitHub Desktop.
One Hot Encoder/Decoder in Octave/Matlab
This file contains hidden or 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 hidden or 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