Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.1 - Português

Change language to:
English - Français - 日本語 - Русский

Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
See the recommended documentation of this function

Ajuda do Scilab >> Estruturas de Dados > setfield

setfield

altera o valor de um elemento de uma mlist, tlist ou list

Seqüência de Chamamento

uL = setfield(a, v, L)

Parâmetros

L
lista do tipo list, tlist ou mlist : a lista cujo componente deve ser alterado.

a
Endereço do componente a ser alterado. Pode ser o nome do campo especificado como uma sequência, ou o índice especificado como um número inteiro positivo. Veja insertion para mais detalhes.

v
Qualquer objeto Scilab : o valor a ser atribuído.

uL
A lista atualizada.

Descrição

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.

Exemplos

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

Ver Também

  • insertion — atribuição ou modificação parcial de variáveis
  • getfield — extração de campos de listas

Histórico

VersãoDescrição
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 Estruturas de Dados struct >>

Copyright (c) 2022-2023 (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 Jan 03 14:35:26 CET 2022