Last active
June 16, 2017 21:17
-
-
Save lordloh/2ecaf742875dfabcb76d32d47514cce3 to your computer and use it in GitHub Desktop.
MATLAB function to convert Boolean values to String.
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 [ out_cell ] = bool2str( bool_in,varargin) | |
%BOOL2STR Converts boolean values to string. | |
% BOOL2STR(B) returns a cell of 'True' or 'False' corresponding to the | |
% boorean values supplied in vector B. | |
% | |
% BOOL2STR(B,{'Noooo!','Yeah!'}) takes custom stings to correspond to the | |
% boolean values. | |
% | |
% Example: | |
% bool2str(logical([1 0 0 1]),{'Noooo!','Yeah!'}) | |
% | |
% ans = | |
% | |
% 1×4 cell array | |
% | |
% 'Yeah!' 'Noooo!' 'Noooo!' 'Yeah!' | |
% Code by Bharath Bhushan Lohray | |
% https://bharath.lohray.com/ | |
% github: lordloh | |
% bitbucket: lordloh | |
if(nargin==1) | |
str_vals={'False','True'}; | |
elseif(nargin==2) | |
str_vals=varargin{1}; | |
else | |
error('Too many inpute arguments.'); | |
end | |
idx=1+uint8(bool_in); | |
out_cell=str_vals(idx); | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment