嗯,我找到了一個解決方案。這不是很好,但它的工作原理。
所有的文件都可以downloded
對不起,我也喜歡張貼圖片,但我沒有10和聲譽。所以你必須從上面的鏈接中下載它。
這裏主要是skript,下面是一個recursif函數。 Skript也適用於所有其他Simulin車型的巴士。但如果只有一個總線選擇器,它現在才起作用。但編程幾個總線系統和總線選擇器並不多。
% Name_Signals_after_Blocknames
format compact, clear all, clc
cd(''); % Directory where the simulink model is safed
Simulink_Model = ('linearGuide_model.slx');
Simulink_Model = ('Verbindung.slx');
Simulink_Model = ('bus_system.slx');
% Simulink_Model = ('singlebus.slx');
[path, Model_name, ext] = fileparts(Simulink_Model);
BlockPaths = find_system(Model_name,'LookUnderMasks', 'all' ,'Type','Block');
length_Model_name = length(Model_name);
Cellofbusselector = [];
jj = 0;
for ii = 1:length(BlockPaths)
disp(BlockPaths{ii})
porthandles = get_param(BlockPaths{ii}, 'PortHandles');
outporthandles = get_param(porthandles.Outport, 'Line');
Block_Name = BlockPaths{ii};
% if length(outporthandles) > 1 % only give names to outputs of a subsystem, they are also listed in the BlockPaths cell
% warning ('more than one signal wants to get the same name, might be a Subsystem')
% else
if strcmp(BlockPaths{ii}(end-7:end), 'Selector') % you can not change the name of a line connecting a Bus Selector
disp('Here we have a Bus selector')
jj = 1+jj;
Cellofbusselector(jj) = ii;
else
if isempty(outporthandles)
warning(['Block ', Block_Name, ' has no Output'])
elseif length(outporthandles) == 1
if outporthandles == -1 % outporthanldes == 1, when there is no signal attachet to the outport of the block
warning(['Block ', Block_Name, ' has no Output-Signal attached'])
else
Signal_name = BlockPaths{ii}((length_Model_name+2):end);
set_param(outporthandles, 'Name', Signal_name);
end
elseif length(outporthandles) > 1
for jj = 1:length(outporthandles)
if outporthandles{jj} == -1 % outporthanldes == 1, when there is no signal attachet to the outport of the block
Block_Name = BlockPaths{ii};
warning(['Block ', Block_Name, ' has no Output-Signal attached'])
else
Signal_name = [BlockPaths{ii}((length_Model_name+2):end), '_out', num2str(jj)];
set_param(outporthandles{jj}, 'Name', Signal_name);
end
end
end
end
% end
end % for ii = 1:length(BlockPaths)
buscell = get_param(BlockPaths{Cellofbusselector}, 'InputSignals');
[signalname, buslevel, numofsig, busname] = f_get_complete_signalnames(buscell)
%%
signalnamesize = size(signalname);
for ii = 1:signalnamesize(1)
for kk = 1:signalnamesize(2)
if isempty(signalname{ii,kk})
else
nrofbusnames = kk-1;
fullbusname = '';
for i = 1:nrofbusnames
fullbusname = [fullbusname '.' busname{i}];
end
fullsignames{ii,1} = [fullbusname(2:end) '.' signalname{ii,kk}]
end
end
end
下面是從recursiv功能
function [signalname, buslevel, numofsig, busname] = f_get_complete_signalnames(buscell, buslevel, numofsig, signalname, busname)
%% Description
% This function returns the complete signal names which are stored in a
% bus. The name looks something like bus1.bus2.signal1.
if nargin < 2; buslevel = 1; end
if nargin < 3; numofsig = 0; end
if nargin < 4; signalname = {}; end
if nargin < 5; busname = {}; end
buscellsize = size(buscell);
buscellsize(1); % busvert is the vertical dimension of buscell
for kk = 1:buscellsize(1)
if ischar(buscell{kk,1}) && buscellsize(2) == 1
numofsig = numofsig + 1;
signalname{numofsig, buslevel} = buscell{kk,1};
elseif ischar(buscell{kk,1}) && buscellsize(2) == 2
busname{buslevel-1} = buscell{kk,1};
[signalname, buslevel, numofsig, busname] = f_get_complete_signalnames(buscell{kk,2}, buslevel, numofsig, signalname, busname);
elseif iscell(buscell{kk,1}) && buscellsize(2) == 1
buslevel = buslevel+1;
[signalname, buslevel, numofsig, busname] = f_get_complete_signalnames(buscell{kk,1}, buslevel, numofsig, signalname, busname);
buslevel = buslevel-1;
end
end
end
我希望我做這個右邊的代碼。這有助於某人。
期望的輸出是什麼?說一個字符串與所有'chars' contacatenated?我們可以假設'char1'等都是單個字符嗎? –
不,他們是一串字符。我需要公交車上信號的確切名稱,並且公交車上可以有嵌套的公交車。信號的名稱與不同的字符組合在一起。所以名字可以是'busname.nestedbusname'。signalname',但我不知道有多少嵌套總線系統互相嵌套。那就是細胞中細胞的來源。 –
因此,例如'myCell = {'aa',{'bb''cccc'},{'d''ee';'ff''ggg'},{'h',{'iii','jj' }}}'?再一次,準確的結果是什麼? –