[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Automatically Combining Structures
From: |
Etienne Grossmann |
Subject: |
Re: Automatically Combining Structures |
Date: |
Tue, 25 Apr 2006 17:10:13 -0400 |
User-agent: |
Mutt/1.4.2.1i |
Hi Bill,
I use this.
Hth,
Etienne
======================================================================
## z = struct_merge (a,...) - Merge any number of structs
##
## a,... : structs : The structs that will be merged.
##
## z : struct : z has all the fields of a,... If many arguments
##have
## the same field, the value of the last is used.
function a = struct_merge (a,varargin)
va_arg_cnt = 1;
nargin = nargin();
while --nargin
b = nth (varargin, va_arg_cnt++);
## s = ¨;
for [val, key] = b
## s = [s,sprintf (ä.%s=b.%s;",key,key)];
a.(key) = val;
end
## eval (s);
7======================================================================
On Tue, Apr 25, 2006 at 09:35:25AM -0400, Bill Denney wrote:
# Hi,
#
# Is there a way to automatically combine structures? What I'm wanting to
# do is something like:
#
# a.c = 1;
# a.d = 2;
# b.e = 3;
# b.f = 4;
# g = combine(a, b)
#
# g =
# {
# c = 1
# d = 2
# e = 3
# f = 4
# }
#
# Do I have to write the function, or is it included as part of
# octave(-forge)?
#
# Bill
#
# _______________________________________________
# Help-octave mailing list
# address@hidden
# https://www.cae.wisc.edu/mailman/listinfo/help-octave
--
Etienne Grossmann ------ http://www.cs.uky.edu/~etienne