MATLAB Matrice Function Question help please?
Ältere Kommentare anzeigen
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.
Akzeptierte Antwort
Weitere Antworten (2)
Image Analyst
am 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 Kommentare
Reelz
am 6 Apr. 2012
Walter Roberson
am 7 Apr. 2012
You have accidentally saved a file under the name toeplitz.m . Remove your file with that name.
Kye Taylor
am 7 Apr. 2012
Impressive debugging :)
Andrei Bobrov
am 7 Apr. 2012
out = abs(bsxfun(@minus,0:4,(0:4)'))
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!