octave: using find() on cell array {} subscript and assigning it to another cell array -
this example in section 6.3.1 comma separated lists generated cell arrays of octave documentation (i browsed through doc command on octave prompt) don't quite understand.
in{1} = [10, 20, 30, 40, 50, 60, 70, 80, 90]; in{2} = inf; in{3} = "last"; in{4} = "first"; out = cell(4, 1); [out{1:3}] = find(in{1 : 3}); % line not understand so @ end of section, have in looking like:
in = { [1,1] = 10 20 30 40 50 60 70 80 90 [1,2] = inf [1,3] = last [1,4] = first } and out looking like:
out = { [1,1] = 1 1 1 1 1 1 1 1 1 [2,1] = 1 2 3 4 5 6 7 8 9 [3,1] = 10 20 30 40 50 60 70 80 90 [4,1] = [](0x0) } here, find called 3 output parameters (forgive me if i'm wrong on calling them output parameters, pretty new octave) [out{1:3}], represents first 3 empty cells of cell array out.
when run find(in{1 : 3}) 3 output parameters, in:
[i,j,k] = find(in{1 : 3}) i get:
i = 1 1 1 1 1 1 1 1 1 j = 1 2 3 4 5 6 7 8 9 k = 10 20 30 40 50 60 70 80 90 which kind of explains why out looks does, when execute in{1:3}, get:
ans = 10 20 30 40 50 60 70 80 90 ans = inf ans = last which 1st 3rd elements of in cell array.
my question is: why find(in{1 : 3}) drop off 2nd , 3rd entries in comma separated list in{1 : 3}?
thank you.
the documentation find should answer question:
when called 3 output arguments, find returns row , column indices of non-zero elements (that's i , j) , vector containing non-zero values (that's k). explains 3 output arguments, not why considers in{1}. answer need @ happens when pass 3 input arguments find in find (x, n, direction):
if 3 inputs given, direction should 1 of "first" or "last", requesting first or last n indices, respectively. however, indices returned in ascending order.
so in{1} x (your data if want), in{2} how many indices find should consider (all of them in case since in{2} = inf) , {in3}is whether find should find first or last indices of vector in{1} (last in case).
Comments
Post a Comment