matlab - matlab coder.extrinsic,定义/初始化更复杂的数据类型
问题描述
在 Simulink 和 coder.extrinsic 中使用 matlab 系统模块。在此链接中,在“使用 mxArrays”标题下,它说 y 必须定义为双精度标量才能使代码正常工作,因为该函数将返回双精度标量。
但是更复杂的数据类型,比如 python 模块呢?澄清:
% foo(x) returns a double scalar
coder.extrinsic('foo', 'py.importlib.import_module');
y = 0; % define y as double scalar
y = foo(x); % works fine
np = ??? ; % how do I define np so that the row below will work?
np = py.importlib.import_module('numpy');
有什么建议么?
解决方案
这里的最佳做法是将所有内容放在同一工作目录下的 matlab (example.m) 函数下,将所有 python 调用和变量放在其中,然后从 Simulink 功能块调用该 matlab 函数。这样你就不会遇到那些可怕的定义错误:
%--- example.m file (exists in the working directory)
function y = example(x)
y = foo(x);
d = py.np.array()
%all python functions go here
end
% ---- inside the Simulink Matlab Function Block
coder.extrinsic('example');
out = 0; %preallocate the output
out = example()
推荐阅读
- angular - 使用 Ionic ion-infinite-scroll 作为子级(Ionic 4)测试任何组件时出错
- json - apache NiFi 将 JSON 转换为 avro
- python - 如何在python中一起添加到列表中的整数?
- python - 是否可以在 selenium 中拦截 websocket 流量?
- python - 如何在 2 个主题中划分 videoCapture 以在 opencv 中更快地处理视频?
- sql - 无法创建名为“delete”的数据库?
- php - 如何从mysql发送图像作为附件
- oracle - 针对 Oracle Server 生产场景的硬件建议
- python - 如何使用 Flask 连接服务器数据库?
- linux - 将 xargs 输出格式化为 grep