使用测试序列块中的外部类

时间:2018-10-19 11:32:28

标签: matlab simulink

根据文档 https://www.mathworks.com/examples/simulink-test/mw/simulinktest-ex80867886-using-an-external-function-from-a-test-sequence-block

我们可以在测试序列中使用外部函数,任何人都不知道是否可以使用类或对象

例如,在测试序列中可以使用任何mscript中声明的函数。

step_1

Stick1_Raw_Data.Stick_Main_Sensor_TRX1_Raw_Data = update_or_initialize_Stick_Raw_Data();

update_or_initialize_Stick_Raw_Data.m

function  Stick_Raw_Data_Stick_Main_Sensor_TRX1_Raw_Data = update_or_initialize_Stick_Raw_Data(x,x_error,y,y_error)
% Sets the inital value or update the value
if nargin < 4 
  Stick_Raw_Data_Stick_Main_Sensor_TRX1_Raw_Data = struct();
  Stick_Raw_Data_Stick_Main_Sensor_TRX1_Raw_Data.X = int16(0);
  Stick_Raw_Data_Stick_Main_Sensor_TRX1_Raw_Data.X_Error = uint8(0);
  Stick_Raw_Data_Stick_Main_Sensor_TRX1_Raw_Data.Y = int16(0);
  Stick_Raw_Data_Stick_Main_Sensor_TRX1_Raw_Data.Y_Error = uint8(0);
else
Stick_Raw_Data_Stick_Main_Sensor_TRX1_Raw_Data = struct();
Stick_Raw_Data_Stick_Main_Sensor_TRX1_Raw_Data.X = int16(x);
Stick_Raw_Data_Stick_Main_Sensor_TRX1_Raw_Data.X_Error = uint8(x_error);
Stick_Raw_Data_Stick_Main_Sensor_TRX1_Raw_Data.Y = int16(y);
Stick_Raw_Data_Stick_Main_Sensor_TRX1_Raw_Data.Y_Error = uint8(y_error);
end
end

但是我们还可以使用它来声明和使用对象吗?

step_3

m = Stick_Raw_Data_Stick_Main_Sensor_TRX_Raw_Data;

%Stick1_Raw_Data.Stick_Main_Sensor_TRX1_Raw_Data = m.update(int16(23),uint8(0),int16(1500),uint8(0));

Stick_Raw_Data_Stick_Main_Sensor_TRX_Raw_Data.m

classdef Stick_Raw_Data_Stick_Main_Sensor_TRX_Raw_Data
   properties
    X
    X_Error
    Y
    Y_Error
   end
   methods
      function r = initialize(obj)
           r.X = int16(0);
           r.X_Error = uint8(0);
           r.Y = int16(0);
           r.Y_Error = uint8(0);
      end
      function r = update(obj,x,x_error,y,y_error)
            r.X = int16(x);
            r.X_Error = uint8(x_error);
            r.Y = int16(y);
            r.Y_Error = uint8(y_error);
      end
   end
end

获取错误图表“测试序列”中有未解决的符号。

0 个答案:

没有答案