⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mwcallfunction.cpp

📁 《精通matlab与c++混合编程》的光盘内容
💻 CPP
字号:
// mwCallFunction.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "matlab.hpp"
#include "matrix.h"

int main(int argc, char* argv[])
{	
	//输入参数个数不定的情况
	//计算下三角阵
	mwArray x=vertcat(horzcat(1,2,3,4),horzcat(5,6,7,8),horzcat(9,10,11,12));
	mwArray trilx,trilx1;
	trilx = tril(x);
	trilx1= tril(x,-1);

	//多个输出参数的情况
	//查找数值阵列中>0.5的元素
	mwArray y=rand(4,4);
	mwArray y1;
	mwArray i,j;
	mxArray * pi,*pj,*py,*py1;	
	int k;
	i=find(&j,&y1,y>0.8);	
	pi = i.GetData();
	pj = j.GetData();
	py = y.GetData();
	py1 = y1.GetData();
	
	cout << "x=:\n"<<x<<endl;
	cout << "tril(x)=:\n"<<trilx<<endl;
	cout << "tril(x,-1)=:\n"<<trilx1<<endl;
	
	cout << "随机数值阵列y=:\n"<<y<<endl;
	if(mxIsLogical(py1))
	{
		cout << "i=find(&j,&y1,y>0.8);\n输出y1为逻辑型变量" <<endl;
	}	
	cout << "随机数值阵列大于0.9的元素为:"<<endl;
	cout.precision(4);	
	for(k=0;k<mxGetNumberOfElements(pi);k++)
	{
		cout << "\t<"
			 <<*((double*)mxGetData(pi)+k)
			 <<","
			 <<*((double*)mxGetData(pj)+k)
			 <<">:"
			 <<*((double*)mxGetData(py)+k)
			 <<endl;	
	}	

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -