宏目录

Submitted by administrator on 周二, 2006-12-19 10:56.

为了方便,在宏目录里的builder和loader分别命名为buildmacros.sce和loadmacros.sce,当然您也可以命名为其他的名字。

一个宏(macros)是以Scilab语言写的一个函数(以.sci结尾)

假设目前我们的工具箱mytoolbox只包含一个.sci文件,函数foo1(见下面的代码)的功能如下:输入一个方阵A,这个函数返回向量XXA对角线上的正数元素。

foo1.sci

function [X]=foo1(A)
	//这个函数返回方阵A对角线上的正数元素
	
	// 检查A的类型和大小
	if  type(A)<>1 then
		error("type of input argument must be a double");
	end
	if  size(A,1)<>size(A,2) then
		error("input argument must be a square matrix");
	end
	//提取对角线上的正数
	X=[];
	for i=1:size(A,1)
		if A(i,i)>0 then
			X($+1)=A(i,i);
		end
	end
endfunction

Copyright © 2005-2006 LIAMA. All rights reserved. 京ICP备05002853号

本网站由中法联合实验室管理,中科院自动化所自由软件协会协助维护