在MATLAB中存储由imline生成的对象的句柄

str*_*its 2 matlab store properties handle line

我试图在数组中存储一组对象句柄.对象是由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]);
Run Code Online (Sandbox Code Playgroud)

Amr*_*mro 6

使用emptystatic方法创建类类型的空数组:

lines = imline.empty(0,10);
for idx=1:10
    line = imline(gca, sortrows(rand(2,2)));
    set(line,'UserData',idx)
    lines(idx) = line;
end
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述