1.0

1.0 | 1 rating Rate this file 15 Downloads (last 30 days) File Size: 1.07 KB File ID: #34540

Band matrix generation

by

 

Generates a band matrix

| Watch this File

File Information
Description

Generate a band matrix by giving the number of diagonals upper and below the main diagonal

Required Products MATLAB
MATLAB release MATLAB 7.13 (R2011b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
13 Jan 2012 Matt Fig

Caitlin, why did you submit two identical files? Did you do this by mistake, perhaps?

Also, you really should at least familiarize yourself with the ONES function in MATLAB, it would be most useful in your function...

11 Jan 2012 Duane Hanselman

Start with a matrix of zeros, change all the values to 1 individually through a nested for loop, then use another nested for loop to change some of them back to zeros.
The author at least deserves credit for preallocating memory.
This is why so much effort was put into implementing JIT.

Here is the entirety of what is in this file:

function [G]=bandmatrix(n,k1,k2)
G=zeros(n,n);
for i=1:n
for j=1:n
G(i,j)=1;
end
end
for i=1:n
for j=1:n
if (j<i-k1) G(i,j)=0;
end
if(j>i+k2) G(i,j)=0;
end
end
end

Contact us