【发布时间】:2011-10-11 23:46:02
【问题描述】:
我正在尝试将一组对象句柄存储在一个数组中。这些对象是由 imline(.) 生成的一系列线条。我想存储句柄,以便能够更改所需行的属性(在本例中为位置)。
我知道如何执行此操作 - 但是,当我尝试使用线句柄填充矩阵时,会发生错误 - MATLAB 指出无法从 IMLINE 转换为 DOUBLE。其他类型的对象不会发生这种情况。有没有办法绕过这个?
这里有一些伪代码需要澄清:
lines=zeros(1,x); % defining empty storage matrix
for idx=1:x
line=imline(ax_handl,[x_1 y_1; x_2 y_2])
set(line,'UserData',idx) % in order to identify independent lines with the number
lines(idx)=line; % here I try to store a line handle as it's made
end
% now in the function responsible for motion of objects, I assign new position to line
line_num=get(gco,'UserData'); % this relates other objects associated with line number
setPosition(lines(line_num),[a b; c d]);
【问题讨论】:
-
一些代码示例将有助于理解您的问题(我没有问题分配带有 imline 句柄对象的矩阵条目)
-
@Adam,你能插入一个 sn-p 来演示你如何填充矩阵吗?
-
上面的代码展示了我在理论上尝试做的事情。
-
@Adam,请看我对这个问题的回答。它解决了这个问题。您需要更改预先分配的方式才能使其正常工作。默认情况下,Matlab 变量为
double。
标签: matlab properties line store handle