概述
VS2012设置
项目–项目属性–配置属性–VC++目录–包含目录 D:MATLABR2016aexterninclude
项目–项目属性–配置属性–VC++目录–库目录
D:MATLABR2016aexternlibwin64microsoft
添加依赖项有两种方法:
方法一:项目中设置
项目–项目属性–配置属性–链接器–输入–添加依赖项
libmx.lib
libmat.lib
libmex.lib
mclmcr.lib
mclmcrrt.lib
libemlrt.lib
libeng.lib
libfixedpoint.lib
libcovrt.lib
方法二:程序中添加
#pragma comment(lib,“libmx.lib”)
#pragma comment(lib,“libmat.lib”)
#pragma comment(lib,“libmex.lib”)
#pragma comment(lib,“mclmcr.lib”)
#pragma comment(lib,“mclmcrrt.lib”)
#pragma comment(lib,“libemlrt.lib”)
#pragma comment(lib,“libeng.lib”)
#pragma comment(lib,“libfixedpoint.lib”)
#pragma comment(lib,“libcovrt.lib”)
计算机–属性–高级系统设置–环境变量–系统变量–Path–新建
D:MATLABR2016abinwin64
matlab程序
pt.m文件
clc;clear;close all;
% 定义点(x,y,z)
x = randn(50,1);
xmax = max(x);
xmin = min(x);
y = randn(50,1);
ymax = max(y);
ymin = min(y);
z = exp(sin(x.^2)) + exp(cos(y.^2));
N = 500; % 每个维度的数据点数
% 网格化x,y二维空间
[X,Y] = meshgrid(linspace(xmin,xmax,N),linspace(ymin,ymax,N));
% 采用插值法扩展数据,可用方法有'linear'(default)|'nearest'|'natural'|'cubic'|'v4'|
Z = griddata(x,y,z,X,Y,'v4');
%% 等高线法
figure('NumberTitle','off','Name','等高线法','Color','w','MenuBar','none','ToolBar','none');
contourf(X,Y,Z,N, 'LineColor','none');
colormap('jet');
colorbar;
axis off;
%{
%% 投影图法
figure('NumberTitle','off','Name','投影图法','Color','w','MenuBar','none','ToolBar','none');
surf(X,Y,Z,'LineStyle','none');
xlim([min(X(:)) max(X(:))]);
ylim([min(Y(:)) max(Y(:))]);
axis off;
colormap('jet');
colorbar;
shading interp;
view(0,90);
%% imagesc法
figure('NumberTitle','off','Name','imagesc法','Color','w','MenuBar','none','ToolBar','none');
% 因为图像坐标和笛卡尔坐标起始位置不一样,需要上下翻转
imagesc(flipud(Z));
colormap('jet');
colorbar;
axis off;
%% pcolor法
figure('NumberTitle','off','Name','pcolor法','Color','w','MenuBar','none','ToolBar','none');
pcolor(X,Y,Z);
colormap('jet');
colorbar;
shading interp;
axis off;
%}
VS2012控制台程序
matlab.cpp文件
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "engine.h"
// 方法一
#pragma comment(lib,"libmx.lib")
#pragma comment(lib,"libmat.lib")
#pragma comment(lib,"libmex.lib")
#pragma comment(lib,"mclmcr.lib")
#pragma comment(lib,"mclmcrrt.lib")
#pragma comment(lib,"libemlrt.lib")
#pragma comment(lib,"libeng.lib")
#pragma comment(lib,"libfixedpoint.lib")
#pragma comment(lib,"libcovrt.lib")
int _tmain(int argc, _TCHAR* argv[])
{
Engine *ep;
if (!(ep = engOpen("