Wednesday, July 22, 2009

Lists in Scilab

Hi everybody, I couldn't post anything last week because I was in a retreat.

Let's study something about lists in Scilab now.

Lists are a type of variables like vectors, but each element may be of any type.

In vectors, all elements are of the same type (vectors of integers, doubles, strings, etc...).

In lists, we may have many types of variables.


Creating a list:

Scilab has a function called list(.) and it may be used with any quantity of elements. Look the examples:


-->person1 = list("Josh", 25, 1.8, 80, "soccer");

-->person2 = list("Mary", 22, 1.6, 55, "tennis");

-->person3 = list("Peter", 30, 1.75, 100, "chess");

-->person1
person1 =


person1(1)

Josh

person1(2)

25.

person1(3)

1.8

person1(4)

80.

person1(5)

soccer

-->person2
person2 =


person2(1)

Mary

person2(2)

22.

person2(3)

1.6

person2(4)

55.

person2(5)

tennis

-->person3
person3 =


person3(1)

Peter

person3(2)

30.

person3(3)

1.75

person3(4)

100.

person3(5)

chess



Each person has five informations:

  1. Name
  2. Age
  3. Height
  4. Weight
  5. Favorite sport

But, if we want to insert more informations, then we can do:

-->person1($ + 1) = "male"
person1 =


person1(1)

Josh

person1(2)

25.

person1(3)

1.8

person1(4)

80.

person1(5)

soccer

person1(6)

male

-->person2($ + 1) = "female"
person2 =


person2(1)

Mary

person2(2)

22.

person2(3)

1.6

person2(4)

55.

person2(5)

tennis

person2(6)

female

-->person3($ + 1) = "male"
person3 =


person3(1)

Peter

person3(2)

30.

person3(3)

1.75

person3(4)

100.

person3(5)

chess

person3(6)

male


The indexes may be manipulated for insert new elements in any point of the list.

If anyone has any question about lists (or others subjects), I can try to answer.

No comments: