File Exchange

image thumbnail

Band matrix generation

version 1.0 (1.07 KB) by

Generates a band matrix

0 Downloads

Updated

View License

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

Comments and Ratings (2)

Loginatorist

Loginatorist (view profile)

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...

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

MATLAB Release
MATLAB 7.13 (R2011b)
Tags Add Tags

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video