How to use a dynamic name as a node in VRML?

1 回表示 (過去 30 日間)
Fred
Fred 2013 年 7 月 22 日
Hello everybody!
The situation: I would like to create several nodes part_1, part_2,..., part_n with shape_1, shape_2,..., shape_n within a root in VRML. To do so, I could simply write:
pipe=vrworld('');
open(pipe);
vrnode(pipe,'part_1','Transform');
vrnode(pipe.part_1,'children','shape_1','Shape');
vrnode(pipe,'part_2','Transform');
vrnode(pipe.part_2,'children','shape_2','Shape');
...
vrnode(pipe,'part_n','Transform');
vrnode(pipe.part_n,'children','shape_n','Shape');
As you see, this requires me to type the commands manually n times :(
Is it possible create a loop that keeps doing this for me?
Something like this?
for i=1:n
a=['part_' num2str(i)];
b=['shape_' num2str(i)];
vrnode(pipe,a,'Transform');
vrnode(pipe.a,'children',b,'Shape');
end
Unfortunately the last command before the end causes problems
Error using vrnode (line 92)
Node 'a' not found.
Any suggestions?
Thanks a lot!
Regards Fred

採用された回答

Fred
Fred 2013 年 7 月 23 日
Hello everybody! I figured out how to solve the problem :)
It was explained here :
If someone is having the same problem, here comes the solution:
for i=1:n
a=['part_' num2str(i)];
b=['shape_' num2str(i)];
vrnode(pipe,a,'Transform');
vrnode(pipe.(a),'children',b,'Shape');
end
The brackets are needed to read the variable a :)
Regards Fred

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by