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

📄 cell.java

📁 JAVA 数学程序库 提供常规的数值计算程序包
💻 JAVA
字号:
package jmathlib.toolbox.general;

import jmathlib.core.tokens.*;
import jmathlib.core.tokens.numbertokens.DoubleNumberToken;
import jmathlib.core.functions.ExternalFunction;

/**An external function for creating matrices that consist of zeros          *
 * everywhere except in the diagonal. The diagonal consists of ones.         *                        
 * (e.g.: eye(3) will return a 3-by-3 matrix [1,0,0;0,1,0;0,0,1],            *
 *  eye(4,3) will return a 4-by-3 matrix with diagonal set to 1              */
public class cell extends ExternalFunction
{
	/**returns a cell array 
	@param operands[0] = number of rows
	@param operands[1] = number of columns */
	public OperandToken evaluate(Token[] operands)
	{
		// at least one operands (e.g. cell(n) )
		if (getNArgIn(operands) < 1)
			throwMathLibException("cell: number of arguments < 1");
            
		if (!(operands[0] instanceof DoubleNumberToken)) return null;
		
		int rows    = (int)(((DoubleNumberToken)operands[0]).getReValues())[0][0];
		int columns = rows;

		// two operands (e.g. cell(n,m) )
		if (operands.length == 2) 
		{
			if (operands[1] == null)                   
				throwMathLibException("cell: arg2 is null");
			if (!(operands[1] instanceof DoubleNumberToken)) 
				throwMathLibException("cell: arg2 not a number");

			columns = (int)((DoubleNumberToken)operands[1]).getReValues()[0][0];
		}
		
		// only positive indices
		if ((rows <= 0) || (columns <= 0)) return null;

		// create cell array
		OperandToken   values[][] = new OperandToken[rows][columns];
		CellArrayToken cellArray  = new CellArrayToken(values);

		return cellArray;		

	} // end eval
}

/*
@GROUP
general
@SYNTAX
matrix = cell("a",7,"b",9)
@DOC
creates a cell array
@NOTES
@EXAMPLES
<programlisting>
matrix = cell("a",7,"b",9)
d.value = 33; d.name="hello"
</programlisting>
@SEE
struct, iscell, isstruct
*/

⌨️ 快捷键说明

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