suppose
…
a = (3-elements list)
(1) = [4,5]
(2) = [5,6]
(3) = [6,7]
…
I want to get the second and third element of this list.
So I choose
…
B = [1x2 double]
-
…
and get only
…
a(B)
ans = [1x2 double]
-
…
However for scalars this works: For
…
b = [3x1 double]
…
I get
…
b(B)
ans = [2x1 double]
…
What is wrong?
Hello and welcome to Scilab’s discourse !
In general (when the index is not a scalar), list indexing yields multiple output arguments (not a list), you have to either give the right number of objects in the lhs:
l = list(1,2,3,4);
[a,b] = l(2:3)
a =
2.
b =
3.
otherwise you only get the first output in ans
, or rebuild a list :
list(l(2:3))
ans = (2-elements list)
(1) = 2
(2) = 3
S.
Thanks, finally I got it. In my example I simply write list(a(B)) instead of a(B)
Cheers wingfour
Similar question: How can I select say the third row of a 5x4 matrix?
Sorry I found an answer myself
1 Like
Another remark: I have a hard time to understand the explanation of the command vec2list: it says the bigvector is a m by n matrix, and the varsizes entry
is a n by 2 matrix. But in the examples bigvector = 1:4, so m = 1, n = 4, and in the second example varsizes is a 2 by 2 and not a 4 by 2 matrix as requested.
Moreover, in the result of the second example, why does the first row have a ; whereas the second row has a , ??
Hello,
I agree with you, the documentation of vec2list() is awfull…
S.