ApplyInjection.m 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. function ApplyInjection(injection, connection, modelPorts)
  2. %SET_INJ 设置注入信号
  3. %
  4. [conn_type, conn_name] = SelectConnection(injection.tag, connection);
  5. if conn_type == 's' || conn_type == 'p'
  6. if conn_type == 's'
  7. ch = SelectPort(modelPorts.Software, conn_name);
  8. elseif conn_type == 'p'
  9. ch = SelectPort(modelPorts.Physical, conn_name);
  10. end
  11. SetPortSignal(ch, ConstructSignal(injection.time, injection.value));
  12. SetPortEnable(ch, injection.enable');
  13. if isfield(injection.option, 'through')
  14. SetPortThrough(ch, injection.option.through);
  15. end
  16. if isfield(injection.option, 'interpolation')
  17. SetPortInterpolation(ch, injection.option.interpolation);
  18. end
  19. end
  20. end
  21. function Signal = ConstructSignal(time, value)
  22. if length(time) == 1
  23. if time == 0
  24. Signal = value;
  25. else
  26. Signal = [0 0; time value];
  27. end
  28. else
  29. Signal = [time value];
  30. end
  31. end