Create input port from .m file
1 回表示 (過去 30 日間)
古いコメントを表示
I have bus signals , which is mentioned in .m file ,
I need to make the model with individual signal not as bus interface.
Any script to create inport as individual signal from the .mfile
0 件のコメント
回答 (1 件)
Rahul
2024 年 8 月 29 日
I understand that you have some bus signals mentioned in a '.m' file. Further you need to make a model with individual signals as inports using a script.
You can follow the following method:
run('your_bus_signals_file.m'); % Using 'run' function to load the bus data
% Replace with your actual .m file name
modelName = 'BusSignalsModel';
new_system(modelName);
open_system(modelName);
% Here assuming that the signals are stored in a 'struct' called 'busData'
% You can change this accordingly if the data is stored otherwise.
signalNames = fieldnames(busData);
% Using a loop adding all inport blocks to the model
for i = 1:length(signalNames)
% Creating inport using 'add_block' function
blockName = ['Inport', num2str(i)];
add_block('simulink/Sources/In1', [modelName, '/', blockName]);
% Setting properties of the inport
set_param([modelName, '/', blockName], 'Name', signalNames{i});
set_param([modelName, '/', blockName], 'Position', [30, 30 + 50*i, 60, 50 + 50*i]);
end
save_system(modelName);
open_system(modelName);
You can refer to the following documentations for your reference:
'fieldnames': https://www.mathworks.com/help/releases/R2024a/matlab/ref/fieldnames.html?searchHighlight=fieldnames&s_tid=doc_srchtitle
Hope this helps! Thanks.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Schedule Model Components についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!