subsasgn.
重新定义下标作业
句法
a = subsasgn(a,s,b)
描述
a = subsasgn(a,s,b)
由matlab打电话®对于语法a(i)= b
那一种{i} = B
, 要么A.I = B.
什么时候一种
是一个对象。
Matlab使用内置subsasgn.
function to interpret indexed assignment statements. Modify the indexed assignment behavior of classes by overloadingsubsasgn.
在课堂里。
笔记
你必须打电话subsasgn.
使用输出参数。subsasgn.
不修改索引操作中使用的对象(第一个输入参数)。您必须分配输出以获取修改后的对象。
输入参数
|
用于索引操作的对象 |
|
结构有两个字段,
|
|
分配值(赋值语句的右侧) |
输出参数
|
Result of the assignment statement, which is the modified object passed in as the first argument. If your implementation of a |
例子
一种rgument values for thesubsasgn.
对于显示的表达式:
a(1:2,:) = b;
语法一种(1:2,:) = B
呼叫a = subsasgn(a,s,b)
在哪里S.
是一种结构s.type ='()'
ands.subs = {1:2,':'}
。结肠人物(':'
)表示将冒号作为下标。
对于表达式:
一种{1:2} = B;
语法一种{1:2} = B
呼叫a = subsasgn(a,s,b)
在哪里s.type ='{}'
ands.subs = {[1 2]}
。
对于表达式:
A.Field = B;
语法A.Field = B.
呼叫a = subsasgn(a,s,b)
在哪里s.type ='。'
ands.subs ='field'
。
对于表达式:
a(1,2)。名称(3:5)= b;
S.imple calls combine in a straightforward way for more complicated indexing expressions. In such cases,长度
是订户级别的数量。例如,a(1,2)。名称(3:5)= b
呼叫a = subsasgn(a,s,b)
在哪里S.
是一个3×1阵列结构,具有以下值:
S.(1).type = '()' |
s(2).type ='。' |
s(3).type ='()' |
s(1).subs = {1,2} |
s(2).subs ='name' |
s(3).subs = {[3 4 5]} |
提示
在这内subsasgn.
method defined by a class, MATLAB calls the built-insubsasgn.
。调用内置允许您在定义专门索引时使用默认索引行为。有关更多信息,请参阅内置子反映和subsasgn调用方法中。
算法
在作业中一种(J,K,...) = B(M,N,...)
,下标j
那K.
那M.
那N.
等等,可以是标量,矢量或数组,当所有以下内容都是真的:
指定的下标数
B.
那excluding trailing subscripts equal to 1, does not exceed the value returned byndims(b)
。指定的非卡尔下标数
一种
等于指定的非卡尔下标数B.
。例如,A(5,1:4,1,2)= B(5:8)
is valid because both sides of the equation use one nonscalar subscript.指定的所有非卡尔下标的订单和长度
一种
匹配指定的Nonscalar下标的订单和长度B.
。例如,a(1:4,3,3:9)= B(5:8,1:7)
is valid because both sides of the equation (ignoring the one scalar subscript3.
)使用4个元素下标,然后是7元用户下标。