This repository has been archived by the owner. It is now read-only.
Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ImageIO/utils/structmap.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
28 lines (23 sloc)
916 Bytes
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 tag = structmap(tagcode, map, numprefix) | |
% STRUCTMAP use struct as a map between field names and values | |
% TAG = STRUCTMAP(TAGCODE, MAP, [NUMPREFIX]) | |
% | |
% Unfortunately, MatLab structs cannot have numerical field names, so we must | |
% use a hack NUMPREFIX. A better solution would be to use cell arrays and OO | |
% programming. | |
% | |
% Peter Li 30-Aug-05 | |
% Some rights reserved. Licensed under Creative Commons: http://creativecommons.org/licenses/by-nc-sa/3.0/ | |
narginchk(2, 3); | |
if nargin < 3, numprefix = 'x'; end % Default NUMPREFIX hack for numerical fields | |
if ~isstruct(map), error('Second argument must be a struct map'); end | |
if isnumeric(tagcode), | |
tagcode = [numprefix num2str(tagcode)]; | |
elseif ~ischar(tagcode), | |
error('Function ''structmap'' is defined for tagcode values of class numeric and char only'); | |
end | |
if isfield(map, tagcode), | |
tag = map.(tagcode); | |
else | |
tag = []; | |
end | |