problem with automized add_block destinations

6 visualizaciones (últimos 30 días)
Davide Maglione
Davide Maglione el 8 de Mayo de 2020
Comentada: Ameer Hamza el 9 de Mayo de 2020
hello,
I am using the add_block function to automatize the creation of a model in simulink. I have stored the block names in a column of a table data, i would like to add the blocks and automatically change their names according to the string data of the table. Here is the code:
nL = numel(data.X)
for i=1:nl
h=add_block('MyLibrary/BlockName' , ['MyModel/',data.Names(i)])
end
here is the error message:
"Invalid destination block specification."
data.Names is a string column of the table data. I have tried using another column of the table
for i=1:nl
h=add_block('MyLibrary/BlockName' , ['MyModel/',num2str(data.X(i))])
end
and this works perfectly! What i am missing? please help! Thank you all!
  4 comentarios
Sulaymon Eshkabilov
Sulaymon Eshkabilov el 8 de Mayo de 2020
you are accessing to your stored created block names in strings via their index numbers. That is it.
Davide Maglione
Davide Maglione el 8 de Mayo de 2020
ok, how can i fix this problem? thank you for answering me

Iniciar sesión para comentar.

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 8 de Mayo de 2020
Editada: Ameer Hamza el 8 de Mayo de 2020
Change the line to this
h=add_block('MyLibrary/BlockName' , ['MyModel/',char(data.Names(i))])
%^ add char here
  6 comentarios
Davide Maglione
Davide Maglione el 9 de Mayo de 2020
now is all clear, thank you very much
Ameer Hamza
Ameer Hamza el 9 de Mayo de 2020
I am glad to be of help.

Iniciar sesión para comentar.

Más respuestas (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 8 de Mayo de 2020
you are accessing to your stored created block names in strings via their index numbers. That is it.

Community Treasure Hunt

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

Start Hunting!

Translated by