0
Follow
0
View

matlab simulink m files interact with simulink

edith0312 注册会员
2023-02-26 19:11

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.

About the Author

Question Info

Publish Time
2023-02-26 19:11
Update Time
2023-02-26 19:11

Related Question

如何在只有一个公式的情况下用matlab曲线拟合

内存映射在生成Autosar兼容的C代码与MATLAB

MATLAB仿真信号与系统

matlab图像 传递函数得到数据

Android Files.delete()使用try-catch依旧出错

Interactive Brokers API(IBAPI) reqMktData对于拍卖量和拍卖不平衡返回相同的数字

matlab求一组数字的组合数(不重复)

matlab中的mpc模型代码

matlab怎么使用使用for循环达到下图的效果

【matlab】plot设置坐标轴参数