MATLAB: Creating an 8×8 matrix using “diag” helpMATLABmatrix So im trying to create an 8×8 matrix with 2's in the diagonal but 0s everywhere else. I used diag(8,8)*0 + 2 but that gived me 2's everywhere. Best Answer 2*eye(8) Related SolutionsMATLAB: Change diagonal place a= magic(3)a = 8 1 6 3 5 7 4 9 2>> b=a;>> for i =2:size(a,1)b(i,1:i)= fliplr(a(i,1:i));endbb = 8 1 6 5 3 7 2 9 4 MATLAB: Extracting matrix diagonal with diag(A) Does this fix your problem?a = eye(4,4) == 1;diag(a)While the diag function works fine, if you have a variable named diag (not a good idea--give it a unique name that isn't the same as a builtin function), it expects a logical, not double, input for indexing. Related QuestionAccess Diagonal Matrix ElementDo I get Out of memory
Best Answer