MATLAB: NxN matrix with 2s on main diagonal matrix How do I create NxN matrix which has 2s on main diagonal, -1s on diagonal above and below 2s and -1 last element (Nth) in the first row and first element in Nth row. Best Answer N = 8; %e.g.m = full(gallery('tridiag', N));m([N, (N-1)*N+1]) = -1 Related SolutionsMATLAB: How to create an n by n wilkinson matrix using diag n = 10;W = spdiags([n:-1:1; n*ones(1,n)]',[0 1],n,n); MATLAB: Adding 2s compliment notation to a function d = hex2dec (d);if d > 2^23-1; d = 2^24 - d; endp = hex2dec (p);if p > 2^15-1; p = 2^16 - p; endt = hex2dec (t);if t > 2^15-1; t = 2^16 - t; end Related QuestionWhat’s the best way to build a block sparse matrix whose entries are diagonal matricesRuns of 1s and 2s in a long vectorCreating Matrix Using Existing Matrix121 by 121 Sparse MatrixHow can i create a 400 by 400 matrix with a pattern
Best Answer