M.ain Content

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.不修改索引操作中使用的对象(第一个输入参数)。您必须分配输出以获取修改后的对象。

输入参数

一种

用于索引操作的对象

S.

结构有两个字段,类型andsubs。对于复合索引表达式,S.是一系列结构,一个用于每个索引级别。

  • 类型是A.char载体或串包含(){}, 要么,说明使用的索引类型。

  • subs是包含实际下标的单元数组,字符数组或字符串数​​组。

B.

分配值(赋值语句的右侧)

输出参数

一种

Result of the assignment statement, which is the modified object passed in as the first argument.

If your implementation of asubsasgn.方法分配多个值,使用varargin.对于第三个输入参数。有关更多信息,请参阅句法for subsref, and subsasgn Methods

例子

一种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,...),下标jK.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元用户下标。

扩展能力

Introduced before R2006a