matlabpropertiessignalslinesimulink

Programmatically Labeling a Signal in Simulink


I'm attempting to write a script that generates a basic Simulink model and I'd like to know if there's a way to programmatically label a signal line. I've looked at the add_line function (which is what I'm using to add the lines), but I don't see an option for defining anything like a Name or Label property.

Is there a way to do this?


Solution

  • Using the currently selected block gcb or the name of the block whose output signal you want to name, you can write

    name = gcb
    h = get_param(name, 'PortHandles')
    
    h = 
      Inport: [72.0029 73.0029]
     Outport: 74.0029
      Enable: []
     Trigger: []
       State: []
       LConn: []
       RConn: []
    Ifaction: []
    
    set(h.Outport(1), 'SignalNameFromLabel', 'output_sig')