Part of the answer refers to GPT, GPT_Pro better solve the problem
Matlab m file and Simulink interaction is a two-way interaction, That is, Matlab can transmit data to Simulink, and Simulink can transmit data back to Matlab. The interaction between Matlab and Simulink is based on data flow. Therefore, when spapi(5.ty) functions obtained in Matlab are taken as input signals in simulink, the above errors will occur.
This is because the spapi(5.ty) functions obtained in Matlab, if they are to be used as input signals in simulink, must organize the data according to the format required in Simulink.
In general, the input signal expected From Workspace module in Simulink is the structure of MATLAB time series object, that is, a data structure in matlab, which contains two fields, time and value. That is, the module From Workspace expects the input signal to be an ordered set of signal samples rather than a single signal value.
The sum spapi(5.ty) function obtained in Matlab is not a set of ordered signal samples, but a single signal value, which leads to the above error.
There are two ways to solve this problem.
First, you can use the simout function in the Matlab script file to organize the data into the format required by the module From Workspace. For example:
y = spapi(5.ty) % 这里调用spapi(5.ty)函数来获取信号y
t = 0:0.1:10; % 定义时间t
simout = simout(t,y); % 用simout函数来组织数据
then simout is used as the input signal From Workspace module.
Secondly, the signal can also be exported To Matalb using the module To Workspace in Simulink model, and then the data can be organized using the simout function in the Matlab script file, and then the processed data can be used as the input signal From Workspace module.
Either way, make sure that the input signal From the Workspace module is formatted correctly.
If the answer is helpful, please accept it.