开发者

What is the meaning of a dollar symbol ($) in SciLab?

开发者 https://www.devze.com 2022-12-17 22:45 出处:网络
What is the meaning of a dollar symbol ($) in SciLab? EDIT: What I meant was dollar symbol 开发者_JAVA百科used in indexing lists. I assumed that\'s the single use of it. The dollar symbol can be used

What is the meaning of a dollar symbol ($) in SciLab?

EDIT: What I meant was dollar symbol 开发者_JAVA百科used in indexing lists. I assumed that's the single use of it.


The dollar symbol can be used to refer to the last element of any vector or matrix.

-->A = [1 2 3 4 5]
 A  =

    1.    2.    3.    4.    5.  

-->A($)
 ans  =

    5.  

-->A($-1)
 ans  =

    4.  


According to the documentation, dollar signs are used to delimit embedded LaTeX.

Starting from Scilab 5.2, it is possible to write LaTeX or MathML expression.

LaTeX texts must start and end by $ (dollar symbol) while MathML texts must start by < and end by > and being syntactically valide.


Apparently (I found the answer in the meantime), dollar symbol in list indexing means the last element of the list.

-->a = list()
 a  =
     ()
-->a(5) = 100
 a  =
// ...
-->a($)
 ans  =
    100.  


$ is the pointer to the last index position.

If you are using it on a list, the last index value is returned.
If you are using it on a variable, the last value for the variable is returned.
(It doesn't store any previous instance as history for variables)

l = [11,22,33,44,55]
k = 1
k = 2
q = "Saurabh"
disp(l,l($),l($-1))
disp(k,k($))
disp(q,q($))

Output

11.   22.   33.   44.   55.

55.

44.

2.

2.

"Saurabh"

"Saurabh"

Please note , k($-1) or q($-1) will give Invalid index.


The first answer is not completely correct. You can user $ as a substitute to the last value of given index, hence using e.g. $-1 or more elaborate expressions is correct:

--> x=rand(1,6)
 x  = 

   0.1121355   0.6856896   0.1531217   0.6970851   0.8415518   0.4062025

--> x($-1)
 ans  =

   0.8415518

--> x($/2)
 ans  =

   0.1531217
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号