octave:2> v=reshape(1:9,3,3) v = 1 4 7 2 5 8 3 6 9 octave:3> A=spdiags(v,-1:1,3,3) A = Compressed Column Sparse (rows = 3, cols = 3, nnz = 7 [78%]) (1, 1) -> 4 (2, 1) -> 1 (1, 2) -> 8 (2, 2) -> 5 (3, 2) -> 2 (2, 3) -> 9 (3, 3) -> 6 octave:4> full(A) ans = 4 8 0 1 5 9 0 2 6 octave:5> x=linspace(0,1,10); octave:6> 1/2<=x ans = 0 0 0 0 0 1 1 1 1 1 octave:7> x x = Columns 1 through 8: 0.00000 0.11111 0.22222 0.33333 0.44444 0.55556 0.66667 0.77778 Columns 9 and 10: 0.88889 1.00000 octave:8> diff(x) ans = Columns 1 through 8: 0.11111 0.11111 0.11111 0.11111 0.11111 0.11111 0.11111 0.11111 Column 9: 0.11111 octave:9> x x = Columns 1 through 8: 0.00000 0.11111 0.22222 0.33333 0.44444 0.55556 0.66667 0.77778 Columns 9 and 10: 0.88889 1.00000 octave:10> idx=x>=1/2 idx = 0 0 0 0 0 1 1 1 1 1 octave:11> y(idx)=10 y = 0 0 0 0 0 10 10 10 10 10 octave:12> v=[0,0,0,0,0,1,1,1,1,1] v = 0 0 0 0 0 1 1 1 1 1 octave:13> z(v)=10 error: subscript indices must be either positive integers less than 2^31 or logicals octave:13> whos Variables in the current scope: Attr Name Size Bytes Class ==== ==== ==== ===== ===== A 3x3 100 double ans 1x9 72 double idx 1x10 10 logical v 1x10 80 double x 1x10 80 double y 1x10 80 double Total is 56 elements using 422 bytes octave:14> fem0 ans = 3.5250e-15 ans = 8.0687e-05 octave:15> fem0 ans = 4.7184e-16 ans = 3.2275e-04 octave:16> fem0 ans = 2.7756e-17 ans = 0.0020172 octave:17> fem0 ans = 1.3878e-17 ans = 0.0080687 octave:18> fem0 ans = 4.7184e-16 ans = 3.2275e-04 octave:19> fem0 ans = 4.7184e-16 ans = 3.2275e-04 octave:20> fem0 ans = 3.5250e-15 ans = 8.0687e-05 octave:21> 3.2275e-04/8.0687e-05 ans = 4.0000 octave:22> fem0 ans = 4.5797e-15 ans = 2.0172e-05 octave:23> diary off