matrix - Using a Vector as Indices in Octave -
let's have 1 matrix , 1 vector. possible use values in vector indices select 1 value each row in matrix? here's example of accomplish:
a = [1, 2, 3; 4, 5, 6; 7, 8, 9;] b = [1;3;1] c = a(b) or c = a(:,b) leading c = [1; 6; 7]
of course loop bigger matrices take while. use make logical matrix in following fashion:
a = zeros(3,3) b = [1;3;1] a(b) = 1 = [1, 0, 0; 0, 0, 1; 1, 0, 0]
thanks advice able give me.
you need create linear indices that. following example:
octave-3.8.2> = [1 2 3 4 5 6 7 8 9]; octave-3.8.2> b = [1 3 1]; octave-3.8.2> ind = sub2ind (size (a), 1:rows (a), b); octave-3.8.2> c = a(ind) c = 1 6 7
Comments
Post a Comment