-->x = tlist(['foo', 'A'], rand(2,2));
In truth I have a non-trivial object (an LCD "panel") whose fields are
initialized by reading matrices from files, but the above example will serve
for illustration.
I'd like to write a function that accepts x as an argument and modifies its
data, e.g.
function y = change_foo(x); x.A = rand(3,3); y = x; endfunction
If I make the call
-->y = change_foo(x);
the x will not be changed, but y will be what I wanted x to be. I can, of
course, change x at the top level:
-->x.A = rand(3,3);
but not within a function -- the function only gets a "copy" to work on.
Is there a way to get Scilab to do what I want?
Thanks,
Matthew
The only way I see (staying in pure scilab language) is by :
-->x = change_foo(x);
This is because a function is not allowed to modify
input arguments (but this would be possible with a C interfaced
function). Also I would say that reading a tlist-member is
efficient but modifying one field is not (at least if the
new "value" have not the same "length" as the old one).
Despite this, tlist are nevertheless practical.
hth
Bruno
The way I know is tricky, since scilab does not know about name of
argument, it is working with the copy. If you pass the name of input
variable too (as string)then you you can do the following
function []=change_foo(x,name)
<All your operations with x>
//at the dend:
exestr(name+'=resume(x)')
endfunction