Function that returns an NxN matrix

1 次查看(过去 30 天)
I need to create a function that when a value for N is entered it returns an NxN identity matrix. But this needs to be done without employing Matlab commands which operate on entire matrices, rows, and columns.
  2 个评论
Andrei Bobrov
Andrei Bobrov 2014-10-8
in MATLAB without employing Matlab commands - how?
Stephen23
Stephen23 2014-10-8
All functions require MATLAB commands, starting with the function function.

请先登录,再进行评论。

采纳的回答

Andrei Bobrov
Andrei Bobrov 2014-10-8
for jj = N:-1:1
out(jj,jj) = 1;
end
  5 个评论
Stephen23
Stephen23 2014-10-9
编辑:Stephen23 2014-10-9
Andrei Bobrov: I like the array preallocation through the reversed sequence. That is a nice touch!
Andrei Bobrov
Andrei Bobrov 2014-10-10
Hi Stephen! This is idea by Jan Simon.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by