Skip to content

Instantly share code, notes, and snippets.

@kyamagu
kyamagu / getOutputArguments.m
Last active December 28, 2015 03:58
Get a specified output arguments by index.
function varargout = getOutputArguments(index, function_handle, varargin)
%GETOUTPUTARGUMENTS Get specified output arguments by index.
%
% [argument1, argument2, ...] = getOutputArguments(index, function_handle)
%
% Example
% -------
%
% Getting the second output argument of min().
%
@kyamagu
kyamagu / getOptions.m
Last active December 27, 2015 22:58
Matlab variable argument parser.
function [options, remaining_arguments] = getOptions(options, varargin)
%GETOPTIONS Get options from variable length arguments.
%
% options = getOptions(options, 'option1', value1, 'option2', value2, ...);
% [options, remaining_arguments] = getOptions(options, ...);
%
% GETOPTIONS parses variable length arguments. OPTIONS is a scalar struct of
% default values. Its fields are updated with name-value pairs of variable
% length input arguments.
%
@kyamagu
kyamagu / logger.m
Created October 29, 2013 03:20
Display a log message.
function logger( varargin )
%LOGGER Display a log message.
%
% logger(fmt, param1, param2, ...)
% logger(true)
% logger(false)
%
% LOGGER displays a log message using the printf arguments. LOGGER takes
% format string FMT followed by parameters for substituion.
%
@kyamagu
kyamagu / strjoin.m
Created October 29, 2013 03:13
Concatenate an array into a single string.
function output = strjoin(input, separator)
%STRJOIN Concatenate an array into a single string.
%
% S = strjoin(C)
% S = strjoin(C, separator)
%
% Description
%
% S = strjoin(C) takes an array C and returns a string S which concatenates
% array elements with comma. C can be a cell array of strings, a character
@kyamagu
kyamagu / md5.m
Created October 29, 2013 02:58
Calculate MD5 digest.
function digest = md5(value)
%MD5 Calculate MD5 digest.
digest = org.apache.commons.codec.digest.DigestUtils.md5(value)';
digest = typecast(digest, 'uint8');
end
@kyamagu
kyamagu / hash.m
Created October 29, 2013 02:57
Calculate a hash value for a string or a numeric/logical array.
function number = hash(value)
%HASH Calculate a hash for a string or a numeric/logical array.
if ~ischar(value)
value = num2str(value);
end
number = typecast(int32(java.lang.String(value).hashCode()), 'uint32');
end