Extracting available Bus signals in a nested Bus recursively.
    10 ビュー (過去 30 日間)
  
       古いコメントを表示
    
I have some nested Bus objects in the workspace which are similar to the example "Create Bus Objects from Bus Element Objects" (https://de.mathworks.com/help/simulink/slref/simulink.bus.html). Now I am trying to access the available signal names by using a recursive function.
This is the code:
function signals = extract_bus_signals(bus_obj)
signals = {};
tempVal = bus_obj.Elements;
i_end = size(tempVal,1);
% loop through each element in the bus object
for i = 1:i_end
    % check if the element is a bus object
    if contains(string(tempVal(i,1).DataType),'Bus')
        nested_bus_name = extractAfter(tempVal(i,1).DataType, 'Bus: ');
        extract_bus_signals((nested_bus_name));
    else
        % add the name of the signal to the overall signals list
        signals{end+1} = bus_obj.Elements(i).Name;
    end
end
The error that I am getting is :
Dot indexing is not supported for variables of this type.
Error in extract_bus_signals12 (line 5)
tempVal = bus_obj.Elements;
Error in extract_bus_signals12 (line 14)
        extract_bus_signals12((nested_bus_name));
I believe I am getting this error because when I pass 1st nested Bus name( 'NestedBus' ) which I am getting at (  "nested_bus_name = extractAfter(tempVal(i,1).DataType, 'Bus: ');"),  which is a "string" to "bus_obj".  instead of a bus. Any ideas to how to pass the child bus as bus object when calling the function. 
My understanding might be wrong. Any guidance is appreciated.
Thank you
 
 0 件のコメント
回答 (1 件)
  Oguz Kaan Hancioglu
      
 2023 年 2 月 25 日
        Since it is defined is yor base workspace, you can use this,
Mathias Benedek (2023). NSTRUCT2CELL (https://www.mathworks.com/matlabcentral/fileexchange/29908-nstruct2cell), MATLAB Central File Exchange. Retrieved February 25, 2023.
2 件のコメント
  Oguz Kaan Hancioglu
      
 2023 年 2 月 27 日
				Before using the nstuct2cell I used following commands,
portHandles = get_param('bus creater location in sumulink (use gcb)','PortHandles')
After you check the handle of bus creater, you can convert the struct,
portStruct = Simulink.Bus.createMATLABStruct(portHandles.Outport)
you can feed the portStruct to NSTRUCT2CELL  (nstruct2cell(portStruct))
Best
参考
カテゴリ
				Help Center および File Exchange で Matrices and Arrays についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

