write a script that creates identity matrices of any size without using the function eye

2 次查看(过去 30 天)
thank you
  2 个评论
Stephen23
Stephen23 2019-1-27
编辑:Stephen23 2019-1-27
@ Chloe St John: it is not appreciated when you delete your question text. This has the effect of treating us as your own disposable personal assistants, which we are not. If you want private help then you will find plenty of consultants who will gladly take your money and offer whatever private advice you want.
If you are concerned about your tutor or professor finding that you have been given all answers to your homework, then perhaps consider that before posting onto a public forum:

请先登录,再进行评论。

回答(2 个)

Stephen23
Stephen23 2019-1-24
编辑:Stephen23 2019-1-24
Don't use a loop, learn to write simple vectorized code:
N = 5;
M = zeros(N);
M(1:N+1:end) = 1

Kevin Phung
Kevin Phung 2019-1-24
n = zeros(5); %square matrix
for i= 1:size(n,1)
n(i,i) = 1;
end

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by