Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2023.1.0 - 日本語


setfield

mlist, tlist, またはlistの要素の値を変更する

呼び出し手順

uL = setfield(a, v, L)

パラメータ

L
list, tlist, またはmlistリスト:コンポーネントを変更する必要があるリスト.

a
変更するコンポーネントのアドレス. 文字列として指定されたフィールド名, または正の整数として指定されたインデックスのいずれかになります. 詳細については, insertionをご覧ください.

v
任意のScilabオブジェクト:割り当てる値

uL
更新されたリスト

説明

L=setfield(a,v,L) addresses and changes the ith element of a list, in a unified way over lists, tlists and mlists.

For simple lists and for tlists, L=setfield(a,v,L) is equivalent to L(a)=v, that is simpler and should be preferred. The same stands for any mlist if the address a is a field's name.

However, for any mlist L, if i is an index, the insertion L(i)=v is not predefined, in order to let the user define an overload implementing a matrix-oriented insertion, if required. Yet setfield(i,v,L) is always defined, with the same meaning as for other list and tlist types.

For a tlist, setfield(3, v, T) is equivalent to T(3)=v :

T = tlist(['V','a','b'], [%z (1-%z) %z^2], [%f %t %t]);
// The insertion is predefined:
T(3) = [%t %t %f];
T(3)

T = setfield(3, [%f %t %f], T);
T(3)
--> T = tlist(['V','a','b'], [%z (1-%z) %z^2], [%f %t %t]);
--> // The insertion is predefined:
--> T(3) = [%t %t %f];
--> T(3)
 ans  =
  T T F

--> T = setfield(3, [%f %t %f], T);
--> T(3)
 ans  =
  F T F

For a mlist, there is no predefined indexed insertion routine, to let the user define a matrix-oriented insertion overload if required.

M = mlist(['V','a','b'], [%z (1-%z) %z^2], [%f %t %t]);
M.b = [%t %t %t];
M.b                 // OK, while ...
M(3) = [%f %t %f];  // => error

// But a raw direct insertion with setfield() is always possible:
M = setfield(3, [%t %f %t], M);
getfield(3, M)
--> M = mlist(['V','a','b'], [%z (1-%z) %z^2], [%f %t %t]);
--> M.b = [%t %t %t];
--> M.b                 // OK, while ...
 ans  =
  T T T

--> M(3) = [%f %t %f];  // => error
Function not defined for given argument type(s),
  check arguments or define function %b_i_V for overloading.

--> // But a raw direct insertion with setfield() is always possible:
--> M = setfield(3, [%t %f %t], M);
--> getfield(3, M)
 ans  =
  T F T

参照

  • insertion — 変数への部分的な代入または修正
  • getfield — リストのフィールドの展開

履歴

バージョン記述
6.0.0
  • The updated list is now returned, instead of being changed "in place".
  • setfield() can no longer be used for cells arrays.
Report an issue
<< rlist Data Structures struct >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon May 22 12:43:11 CEST 2023