more then one tag on object in figure
10 ビュー (過去 30 日間)
古いコメントを表示
I have a problem whith a line of code in which i have 3 robots with each a seperate tool. Each tool has the tag tool1-3 depending on the robot now the tool is drawn with the line command inside a loop where it extracts vectorised x,y,z values from a struct. The loop is within another loop inside a switch case for each robot.
my initial thought was to maby declare more than one tag to the obj with the use of j for allocating the same line obj ones it's suppoed to redraw it.
code in which the problem stems is this one:
for j = 1: size(td,2) %the td = rd.xyz a
% V 4x4 matrix is the hand position of the robot in the x,y,z plane V(1:3,1:3) = rotation
% V(1:3,4) = translation
p = V(1:3,4); % This is for the starting position of the line
V(1:3,4) = V(1:3,4)+td(1:3,j); % P is the handposition rd.xyz from the TCP!
q = V(1:3,4); % this is the end position of the line from vector in td(:,j)
x = [p(1) q(1)];
y = [p(2) q(2)];
z = [p(3) q(3)];
if isempty(findobj('tag',['tool3',num2str(j)]))
h = line(x,y,z);
set(h,'tag',['tool3',num2str(j)],...
'color','k',...
'linewidth',3)
else
set(findobj('tag',['tool3',num2str(j)],...
'linewidth',3,...
'color','k',...
'xdata',x,...
'ydata',y,...
'zdata',z)
end
end
what i get is a figure that prints multiple tool lines as the robot moves and i need someway to redraw those away for the updated position of the tool.
the thing i'm getting at the moment looks like this:

I might be going at this all wrong and maby whould collect the vectors in seperate x(j) and y(j), z(j) arrays and ones those have been gathered draw the new line with or something.
0 件のコメント
回答 (2 件)
Walter Roberson
2020 年 10 月 26 日
No. The Tag field of an object must be a character vector or a scalar string. The only way to store multiple tags would be to encode them all into a single character vector. But then you cannot findobj() on them as there is no way to ask to process the content of the tags.
You should instead use addprop() to add properties to the objects, in which case you can find them with findobj -property
if ~hasprop(h, 'tool3'); addprop(h, 'tool3'); end
findobj(groot,'-property', 'tool3')
slowlearner
2020 年 10 月 26 日
1 件のコメント
Walter Roberson
2020 年 10 月 26 日
That would create a tag property such as 'tool3tool7' . You would not be able to use findobj() to search for tool3 or tool7 and find those objects.
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!