首页/文章/ 详情

HyperWork必备知识-templex语言4-格式化显示

3月前浏览1774

通过表格形式显示数组,语法如下

Syntax

table( [, ,..., ], , , )

Input

  • array_1

  • An array of values for column 1.

  • array_2

  • An optional array of values for column 2.

  • array_n

  • An optional array of values for column n.

  • format

  • A format descriptor for each column in the table.

  • from

  • The index of the first element in each column.

  • to

  • The index of the last element in each column.






{label = {"zero", "one", "two", "three", "four"} }{c0 = {" ", "I", "II", "III", "IV", "V", "VI"} }{c1 = {0, 1, 2, 3, 4, 5, 6} }{table(label, c0, c1, "%8s %8s %4d", 0, 3)}






{label = {"zero", "one", "two", "three", "four"} }{c0 = {" ", "I", "II", "III", "IV", "V", "VI"} }{c1 = {0, 1, 2, 3, 4, 5, 6} }{table(label, c0, c1, "%8s %8s %4d", 0, 4)}






{label = {"zero", "one", "two", "three", "four"} }{c0 = {" ", "I", "II", "III", "IV", "V", "VI"} }{c1 = {0, 1, 2, 3, 4, 5, 6} }{table(label, c0, c1, "%8s %8s %4d", 1, 6)}


设置字符的格式语法如下:

Syntax

format, %[].[][], []

Input

  • width

  • An optional parameter that specifies the minimum number of characters to be printed.

  • precision

  • An optional parameter that specifies the number of digits to the right of the decimal point.

  • type

  • An optional parameter that specifies the format of the output:

    • i/d

    • integer

    • f

    • floating point

    • e/E

    • scientific notation

    • g/G

    • auto-format

    • o

    • octal

    • x/X

    • hexadecimal

    • c/C

    • single character

    • s/S

    • string

  • optional parameter

  • An optional parameter that displays the output in one of three formats:

    • Displays the contents of an array as comma-separated lists.

    • Displays the contents of an array as elements inside of braces with each element in the array surrounded by braces and separated by commas.

    • Displays the contents of an array as rows and columns of values bounded by vertical bars.







{format, %i, list}{square1 = { {1.3, 2.9},            {3.1, 4.2} } }{square1}{square1, %i, array}{square1, %i, matrix}


Template:




{format, %9.7f}{sin(PI/4)}{sin(PI/4), %5.2f}

Output:



0.70710670.71

计算线性方程






















3x + 4y + 9z = 295x - 3y +  z = 16x +  y +  z =  4{x_coeffs = {  3,  5, 1 }  }{y_coeffs = {  4, -3, 1 }  }{z_coeffs = {  9,  1, 1 }  }{rhs      = { 29, 16, 4 }' }{lhs = {x_coeffs, y_coeffs, z_coeffs}' }{format, %5.2f, matrix}coefficient matrix:{lhs}right hand side:{rhs}determinant:{determinant(lhs)}inverse:{inverse(lhs) , %7.4f}inverse times original:{inverse(lhs) * lhs}answer:{inverse(lhs) * rhs}

Formatting Guidelines

Formatting general output, numeric output, character and string output, and matrices.


Output

Templex writes text to the specified output stream exactly as it appears in the template.

For example:

{X=3}
What is X + 2?
The answer is: {X + 2}

appears as:

What is X + 2?
The answer is: 5

Templex uses standard C format descriptors to format numeric and string output. Format descriptors reserve a specific amount of space in the output text for the value. If more space is reserved than the value requires, the output text is padded with spaces. Numerical values are right justified. String values are left justified.

If no format is specified, each data type uses the default format associated with each variable type or the default template format and the output is not padded. A default template format is created using the Templex statement. format

Format descriptors are placed at the end of an expression. They are separated from the expression by a comma and preceded by a percent sign, %. The following examples illustrate the syntax:

{sqrt(100), %5d}
{cos(t) + sin(3.1415/phi), %12.5f}

Of the twelve spaces in the second example, five spaces are used to display the values to the right of the decimal point. One space is reserved for the decimal point. The six remaining spaces appear to the left of the decimal point as a blank and a zero.

Extra space does not need to be reserved for the leading plus/minus sign. Some operating systems display a blank instead of a plus sign.

Numeric Output

Integer and real values can be displayed in six output formats: integeroctal, hexadecimal, floating point, scientific notation, and value dependent. Descriptors for these formats and examples of their use are given in the following table.

Data FormatDescriptorExampleOutput
Integerd or i
  • {sqrt(10000), %5d}

  • {sin(PI/4), %5i}

  • ••100

  • ••••0

Octalo{100, %4o}•144
Hexadecimalx or X{100, %4X}••64
Floating pointf{sin(PI/4), %6.3f}•0.707
Scientific notatione or E
  • {sin(PI/4), %10.3e}

  • {sin(PI/4), %10.3E}

  • +0.707e+00

  • +0.707E+00

Value-dependentg or G
  • {sin(PI/4), %10.3g}

  • {100, %7.3f}

  • •••••0.707

  • 100.000

Note: The • in the output column indicates blank spaces which are used to pad the output if the reserved space is not completely used. The • does not appear in your output.

The and descriptors automatically determine whether a fixed decimal or exponential notation format should be used, depending on the magnitude of the result. If the magnitude of the value is large, the descriptor uses a capital in the exponent, depending on your operating system’s defaults.gGGE

Character and String Output

Character and string values can be displayed in two output formats, as single characters or as strings. Descriptors for these formats and examples of their use are given in the following table:

Data FormatDescriptorExampleOutput
single characterc{65, %c}A
character strings{"This is a string", %.12s}This is a st
Templex now supports foreign characters with a new registry key, . Setting the registry key to ignores foreign characters while setting the registry key to supports them. You must restart Templex to see the change as it only checks this registry key at start up.templex.hichar01

Matrices

Matrices can be displayed in three output formats: as a comma-separated list, as a list of elements inside braces, and as rows and columns of numbers. The parameters for these three formats and examples of each are given in the following table:

Data FormatDescriptorExampleOutput
comma-separated listslist
{format, %i, list}
{square1 =
{ {1.3, 2.9},
  {3.1, 4.2} } }
{square1}
{1, 2},
{3, 4}
elements inside of bracesarray
{format, %i, array}
{square1 =
{ {1.3, 2.9},
{3.1, 4.2} } }
{square1}
{ {1, 2}, {3, 4} }
rows and columnsmatrix
{format, %3.1f, matrix}
{square1 =
{ {1.3, 2.9},
{3.1, 4.2} } }
{square1}
| 1.3 2.9 |
|         |
| 3.1 4.2 |


来源:TodayCAEer
ACTSystemUMOrigin
著作权归作者所有,欢迎分享,未经许可,不得转载
首次发布时间:2024-08-14
最近编辑:3月前
TodayCAEer
本科 签名征集中
获赞 18粉丝 27文章 242课程 0
点赞
收藏
作者推荐

HyperMesh二次开发-数字网格华容道

以前直板机上最经典的游戏之一,游戏还是以蒙拉丽莎的微笑作为背景图,那时候还不懂怎么玩,只知道瞎点,玩不过去。当然那时候还有麻将连连看和魔法寿司两款游戏,一样的好玩。程序开发逻辑,1、新建一个平板网格。2、新建指定数量的comps。3、取3X3的网格移动到指定的comps中。4、释放网格节点,再对每个comps进行节点缝合。5、在每个comps中心,创建tag标记。6、打乱comps分布顺序。7、用户选择comps与白色的comps交换空间位置。8、while循环交互选择,每次交换位置检测tag是否满足有序的条件。程序第一次运行模型会创建3x3规格的游戏,后续如果需要其他规格的,可以通过函数Klotski加游戏规格,例如Klotski4将创建4x4的游戏。同样经典的数字游戏还有数独HyperMesh二次开发-数独现在我们来看看在HyperMesh里面如何实现。由于软件的限制,我们在选择对应comps后需要按中键才能执行交换过程。一开始我想的很简单,以为随机生成数组就可以了,结果在录制视频的时候才发现存在很大的问题,在最后四个单元格顺序不对,不管怎么移动都无法完成。后面搜索了才知道有逆序数的要求,算是开发过程中的小插曲。程序获取方式,后台回复关键字华容道有的文章需要分享文章后,再回复关键字哦,所以需要发送分享的截图,只回复关键字是不行的哦。来源:TodayCAEer

未登录
还没有评论
课程
培训
服务
行家
VIP会员 学习 福利任务 兑换礼品
下载APP
联系我们
帮助与反馈