Matlab产生可供VC调用的动态链接库的一种方法

在工程实践中,将VC便捷的编程语言与MATLAB强大的仿真功能(生成图形)结合起来是一种十分有益的方法。在考量了多种Matlab与VC混合编程的方法后,发现利用VC调用MATLAB动态链接库(dll)是一种简单实用的方法。本博文即提出一种Matlab产生可供VC调用的动态链接库的方法。

1)工具与环境

MATLAB2011a与Visual Studio 2010。

2)为MATLAB关联VC编译器

在Command Window中运行代码:

mbuild -setup

并在接下来的提示信息下选择VC的编译器。

3)编写MATLAB作图函数.m

如:

function sim_visual()
% read data to matrix
Matrix = load('data_sim_ideal_12G.txt');
%draw semilog coordinate(ideal curve).
x = Matrix(:,1);
y = Matrix(:,2);
semilogx(x,y,'r');
%draw semilog coordinate(calculate curve).
hold on;
Matrix = load('data_sim_o.txt');
x = Matrix(:,1);
y = Matrix(:,2);
semilogx(x,y,'b');
grid on;
hold off;
% plot(x,y,'r-',x,90,'mp');
xlabel('D');
ylabel('E');
title('Attenuation');
legend('ideal','calculate');

end

注:关于参量传递,请参考下一篇博文,VC调用MATLAB动态链接库

你可能感兴趣的:(混合编程)