MATLAB Matrice Function Question help please?
Show older comments
I am trying to write a matlab program which creates an n by n matrix with the following:
a = [0 1 2 3 4; 1 0 1 2 3; 2 1 0 1 2; 3 2 1 0 1; 4 3 2 1 0]
How would I go about doing this?
42 minutes ago
- 4 days left to answer.
Additional Details Also looking like this:
a =
0 1 2 3 4
1 0 1 2 3
2 1 0 1 2
3 2 1 0 1
4 3 2 1 0
Some detailed instruction/help would really help me in clarifying how to program matrices in general.
Accepted Answer
More Answers (2)
Image Analyst
on 6 Apr 2012
For example, write this in the editor window (Use File->New if you have to, or click the blank page icon to get a new editor window):
function m = test1(n)
if nargin >= 1
m = toeplitz(0:n);
else
m = toeplitz(0:4); % Default
warningMessage = sprintf('Using default n of 4');
uiwait(warndlg(warningMessage));
end
and save it as test1.m. Then you can run it without any args and it will use a default of 4, or you can say
>> test1(5)
and it will use an n of 5.
3 Comments
Reelz
on 6 Apr 2012
Walter Roberson
on 7 Apr 2012
You have accidentally saved a file under the name toeplitz.m . Remove your file with that name.
Kye Taylor
on 7 Apr 2012
Impressive debugging :)
Andrei Bobrov
on 7 Apr 2012
out = abs(bsxfun(@minus,0:4,(0:4)'))
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!