Why isn't the 'add_block' function working when giving variable instead of explicit value?

3 visualizaciones (últimos 30 días)
I'm currently trying to add blocks, based on names from an excel list, to my current system. However the add_block function only works when I'm passing it the explicit value of my string. Whenever I'm passing it a variable with the exact same value, its telling me : Invalid destination block specification. Here's my current code which doesn't work. For testing I'm only trying to add the block for the first element of the list. I've included the line of code for which it does actually work.
[num, name_txt] = xlsread('parameterSet.xlsx',1,'A2:A237');
load_system(gcs);
load_system('simulink');
for line = 1:numel(name_txt)
subsystem_name = strcat(gcs, '/');
subsystem_name = strcat(subsystem_name, name_txt(line));
if line == 1
add_block('simulink/Ports & Subsystems/Enabled Subsystem', subsystem_name, 'MakeNameUnique', 'on');
*This works:* add_block('simulink/Ports & Subsystems/Enabled Subsystem', 'DiagnosticsTest/Function_Call_Subsystem/Read_Message/Send_Response/Single_Frame_Response/Another System', 'MakeNameUnique', 'on');
end
end

Respuesta aceptada

Tim Leschinsky
Tim Leschinsky el 2 de Mayo de 2018
EDIT: I've found the problem. Since subsystem_name is a cell array, I only need to access the first element: Which results in:
add_block('simulink/Ports & Subsystems/Enabled Subsystem', subsystem_name{1}, 'MakeNameUnique', 'on');
  1 comentario
Satya jain
Satya jain el 20 de Jul. de 2020
Hello
i am facing the same kinda problem that the name given takes it to an invalid type due to ' ' written on text entries.
Can you help how to solve it

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Subsystems en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by