MATLAB Matrice Function Question help please?
古いコメントを表示
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.
採用された回答
その他の回答 (2 件)
Image Analyst
2012 年 4 月 6 日
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 件のコメント
Reelz
2012 年 4 月 6 日
Walter Roberson
2012 年 4 月 7 日
You have accidentally saved a file under the name toeplitz.m . Remove your file with that name.
Kye Taylor
2012 年 4 月 7 日
Impressive debugging :)
Andrei Bobrov
2012 年 4 月 7 日
out = abs(bsxfun(@minus,0:4,(0:4)'))
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!