View License

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

» Watch video

Highlights from
Band matrix generation

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

Band matrix generation



Generates a band matrix

| Watch this File

File Information

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

Comment only
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)
for i=1:n
for j=1:n
for i=1:n
for j=1:n
if (j<i-k1) G(i,j)=0;
if(j>i+k2) G(i,j)=0;

Contact us