MATLAB: How to create a diagonal matrix with the semibandwidth of 4 diagonal matrix how to create a matrix like this: Best Answer Hi Lin Hongbinnot sure if your picture contains some errors, A(3,1) looks suspicious to me...look at this and tell me if it fits your wishes :)a=1:10;b=11:20;c=21:30;d=31:40;n=length(a);A=zeros(n);% set the restfor i=1:n % rows A(i,i:i+3)=[a(i),b(i),c(i),d(i)];end>> AA = 1 11 21 31 0 0 0 0 0 0 0 0 0 0 2 12 22 32 0 0 0 0 0 0 0 0 0 0 3 13 23 33 0 0 0 0 0 0 0 0 0 0 4 14 24 34 0 0 0 0 0 0 0 0 0 0 5 15 25 35 0 0 0 0 0 0 0 0 0 0 6 16 26 36 0 0 0 0 0 0 0 0 0 0 7 17 27 37 0 0 0 0 0 0 0 0 0 0 8 18 28 38 0 0 0 0 0 0 0 0 0 0 9 19 29 39 0 0 0 0 0 0 0 0 0 0 10 20 30 40if u cut off the first and last column it looks more like your picture (beside A(3,1) and A(3,4) etc is not d3 ...)B=A(1:n,2:n+2)B = 11 21 31 0 0 0 0 0 0 0 0 2 12 22 32 0 0 0 0 0 0 0 0 3 13 23 33 0 0 0 0 0 0 0 0 4 14 24 34 0 0 0 0 0 0 0 0 5 15 25 35 0 0 0 0 0 0 0 0 6 16 26 36 0 0 0 0 0 0 0 0 7 17 27 37 0 0 0 0 0 0 0 0 8 18 28 38 0 0 0 0 0 0 0 0 9 19 29 39 0 0 0 0 0 0 0 0 10 20 30so either matrix A or B might be the answer.But neither A nor B are quadratic. A has size n x n+3 and B: n x n+1 Related SolutionsMATLAB: I want a connectivity matrix of size 30×27 of the form shown in the body below. Please suggest an answer. c1 = 1:2:59 ;c2 = 2:2:60 ;c3 = 3:2:61 ;o = zeros(length(c1),24) ;C = [c1' c2' c3' o] MATLAB: Delete rows and columns with zeros in a multi level cell array matrix. fun = @(in)in(~cellfun(@(x)[strcmp(x,'0')||isempty(x)] , in));result = cellfun(fun, datafi2 , 'UniformOutput', false); Related Question3D matrix summationReturn many value in function.Polyfit not working rightSlicing matrix in efficient way
Best Answer