25 lines
1.0 KiB
Plaintext
25 lines
1.0 KiB
Plaintext
x = <<>>; // create an empty list using strings as identifiers.
|
|
x.red = strtod("0xff0000"); // RLaB doesn't deal with hexadecimal numbers directly. Thus we
|
|
x.green = strtod("0x00ff00"); // convert it to real numbers using ''strtod'' function.
|
|
x.blue = strtod("0x0000ff");
|
|
|
|
// print content of a list
|
|
for (i in members(x))
|
|
{ printf("%8s %06x\n", i, int(x.[i])); } // we have to use ''int'' function to convert reals to integers so "%x" format works
|
|
|
|
// deleting a key/value
|
|
clear (x.red);
|
|
|
|
// we can also use numeric identifiers in the above example
|
|
xid = members(x); // this is a string array
|
|
|
|
for (i in 1:length(xid))
|
|
{ printf("%8s %06x\n", xid[i], int(x.[ xid[i] ])); }
|
|
|
|
// Finally, we can use numerical identifiers
|
|
// Note: ''members'' function orders the list identifiers lexicographically, in other words
|
|
// instead of, say, 1,2,3,4,5,6,7,8,9,10,11 ''members'' returns 1,10,11,2,3,4,5,6,7,8,9
|
|
x = <<>>; // create an empty list
|
|
for (i in 1:5)
|
|
{ x.[i] = i; } // assign to the element of list ''i'' the real value equal to i.
|