 subsasgn - Maple Help

MTM

 subsasgn
 subscript assignment of arrays Calling Sequence subsasgn(A,index,val) Parameters

 A - array or record index - Record, list, or Array val - any expression inplace=truefalse - (optional) default to true Description

 • The subsasgn command mirrors subscript assignment in MATLAB®. Using A(index) = val in MATLAB® will produce the same result as subsasgn(A,index,val).
 • subsasgn returns an array of the same type as A.  The result may be a copy of A.  Typically the returned result will be a reference to the same A that was passed in.
 • Use the calling sequence A := subsasgn(A,index,val) when you want to continue using A as if A[index] := val had been executed.  Assigning A to the result will ensure your code uses the updated version of A when a copy was returned.
 • If you always want a copy of the result use the option inplace=false. With inplace=true, a copy will only be generated if the operation results in an array that is bigger than the input array (has more dimensions, or larger ranges in any dimension).
 • More complicated MATLAB® indexing, such as A(index1).index2(index3) require the use of a Record or array of Records with "type" and "subs" fields to specify the subreference for each indexing operation.  The "type" field can have the values "()", "{}", or ".".  There is no distinction between the first two, "()" and "{}", which indicate array-indexing. The "." type indicates an index into a Record.  The "subs" field contains the actual index value.  For example A(i,j) can be modified up via subsasgn(A,Record(type="()",subs=Array([i,j])),val); Similarly A(i,j).name can be updated via subsasgn(A,< Record(type="()",subs=Array([i,j])) Record(type=".",subs="name") >, val );. Examples

 > $\mathrm{with}\left(\mathrm{MTM},\mathrm{subsasgn}\right):$
 > $A≔\mathrm{Array}\left(\left[\left[1,2\right],\left[3,4\right]\right]\right)$
 ${A}{≔}\left[\begin{array}{cc}{1}& {2}\\ {3}& {4}\end{array}\right]$ (1)
 > $\mathrm{subsasgn}\left(A,\left[1,1\right],5\right)$
 $\left[\begin{array}{cc}{5}& {2}\\ {3}& {4}\end{array}\right]$ (2)
 > $A\left[1,1\right]$
 ${5}$ (3)
 > $R≔\mathrm{Record}\left(\mathrm{name}="Paul"\right)$
 ${R}{≔}{\mathrm{Record}}{}\left({\mathrm{name}}{=}{"Paul"}\right)$ (4)
 > $\mathrm{subsasgn}\left(R,\mathrm{Record}\left(\mathrm{type}=".",':-\mathrm{subs}'="name"\right),"Bryan"\right)$
 ${R}$ (5)
 > $R:-\mathrm{name}$
 ${"Bryan"}$ (6)
 > $B≔\mathrm{Array}\left(\left[\mathrm{Record}\left(\mathrm{name}="Paul"\right),\mathrm{Record}\left(\mathrm{name}="Bryan"\right)\right]\right)$
 ${B}{≔}\left[\begin{array}{cc}{\mathrm{Record}}{}\left({\mathrm{name}}{=}{"Paul"}\right)& {\mathrm{Record}}{}\left({\mathrm{name}}{=}{"Bryan"}\right)\end{array}\right]$ (7)
 > $\mathrm{subsasgn}\left(B,\left[\mathrm{Record}\left(\mathrm{type}="\left(\right)",':-\mathrm{subs}'=⟨2⟩\right),\mathrm{Record}\left(\mathrm{type}=".",':-\mathrm{subs}'="name"\right)\right],"Michael"\right)$
 $\left[\begin{array}{cc}{\mathrm{Record}}{}\left({\mathrm{name}}{=}{"Paul"}\right)& {\mathrm{Record}}{}\left({\mathrm{name}}{=}{"Michael"}\right)\end{array}\right]$ (8)
 > $B\left[2\right]:-\mathrm{name}$
 ${"Michael"}$ (9)