help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to modify structure fields inside functions


From: Ben Abbott
Subject: Re: How to modify structure fields inside functions
Date: Fri, 06 Apr 2012 06:58:17 -0400

On Apr 6, 2012, at 5:23 AM, Bruno Picasso <address@hidden> wrote:

> Hi everybody,
> 
> I need your help to understand how to modify a structure field inside a 
> function. For example:
> 
> >> a.b=3
> a =
> {
>   b =  3
> }
> 
> >> function modify (s)
> > setfield(s,'b',5)
> > endfunction
> 
> >> modify(a)
> ans =
> {
>   b =  5
> }
> 
> >> a.b
> ans =  3
> 
> Thanks for your kind help
> 
> Bruno

function s = modify (s)
s = setfield (s, "b", 5);
end

Or

function s = modify (s)
s.b = 5;
end

Ben


reply via email to

[Prev in Thread] Current Thread [Next in Thread]