Mercurial > hg > ishara
view general/map_fields.m @ 54:9bcf5e133bf0
Added from old stats library.
author | samer |
---|---|
date | Mon, 23 Feb 2015 16:08:09 +0000 |
parents | 3cedfd4549ef |
children |
line wrap: on
line source
% map_fields - Apply function to all member fields of structure % % map_fields :: % (A->B) ~'function from As to Bs', % struct(fields(N,A)) % -> struct(fields(N,B)). % % fields(N,A) denotes a list of struct field type declarates with % names from list N and types all equal to A, eg % fields({'a','b','c'},real) == {a::real, b::real, c::real}. function y=map_fields(fn,x) y=foldl(@(s,f)setfield(s,f,fn(s.(f))),x,fields(x));