comparison scripts/miscellaneous/setfield.m @ 8507:cadc73247d65

style fixes
author John W. Eaton <jwe@octave.org>
date Tue, 13 Jan 2009 14:08:36 -0500
parents a1dbe9d80eee
children eb63fbe60fab
comparison
equal deleted inserted replaced
8506:bc982528de11 8507:cadc73247d65
20 ## @deftypefn {Function File} {[@var{k1}, @dots{}, @var{v1}] =} setfield (@var{s}, @var{k1}, @var{v1}, @dots{}) 20 ## @deftypefn {Function File} {[@var{k1}, @dots{}, @var{v1}] =} setfield (@var{s}, @var{k1}, @var{v1}, @dots{})
21 ## Set field members in a structure. 21 ## Set field members in a structure.
22 ## 22 ##
23 ## @example 23 ## @example
24 ## @group 24 ## @group
25 ## oo(1,1).f0= 1; 25 ## oo(1,1).f0 = 1;
26 ## oo = setfield(oo,@{1,2@},'fd',@{3@},'b', 6); 26 ## oo = setfield (oo, @{1,2@}, "fd", @{3@}, "b", 6);
27 ## oo(1,2).fd(3).b == 6 27 ## oo(1,2).fd(3).b == 6
28 ## @result{} ans = 1 28 ## @result{} ans = 1
29 ## @end group 29 ## @end group
30 ## @end example 30 ## @end example
31 ## 31 ##
32 ## Note that this function could be written 32 ## Note that this function could be written
33 ## 33 ##
34 ## @example 34 ## @example
35 ## i1= @{1,2@}; i2= 'fd'; i3= @{3@}; i4= 'b'; 35 ## i1 = @{1,2@}; i2 = "fd"; i3 = @{3@}; i4 = "b";
36 ## oo( i1@{:@} ).( i2 )( i3@{:@} ).( i4 ) == 6; 36 ## oo(i1@{:@}).(i2)(i3@{:@}).(i4) == 6;
37 ## @end example 37 ## @end example
38 ## @seealso{getfield, rmfield, isfield, isstruct, fieldnames, struct} 38 ## @seealso{getfield, rmfield, isfield, isstruct, fieldnames, struct}
39 ## @end deftypefn 39 ## @end deftypefn
40 40
41 ## Author: Etienne Grossmann <etienne@cs.uky.edu> 41 ## Author: Etienne Grossmann <etienne@cs.uky.edu>
60 endfunction 60 endfunction
61 61
62 %!test 62 %!test
63 %! x.a = "hello"; 63 %! x.a = "hello";
64 %! x = setfield(x,"b","world"); 64 %! x = setfield(x,"b","world");
65 %! y = struct('a','hello','b','world'); 65 %! y = struct("a","hello","b","world");
66 %! assert(x,y); 66 %! assert(x,y);
67 %!test 67 %!test
68 %! oo(1,1).f0= 1; 68 %! oo(1,1).f0= 1;
69 %! oo = setfield(oo,{1,2},'fd',{3},'b', 6); 69 %! oo = setfield(oo,{1,2},"fd",{3},"b", 6);
70 %! assert (oo(1,2).fd(3).b, 6) 70 %! assert (oo(1,2).fd(3).b, 6)