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일

1 개 추천

for jj = N:-1:1
out(jj,jj) = 1;
end

댓글 수: 5

Stephen23
Stephen23 2014년 10월 8일
This uses multiple MATLAB functions: for , colon , end ,...
Andrei Bobrov
Andrei Bobrov 2014년 10월 8일
Hi Stephen! I agree with you.
Michael
Michael 2014년 10월 9일
So I tried this in matlab and no matter what value you enter for N it displays a 4x4 identity matrix.
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개)

카테고리

도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2014년 10월 8일

댓글:

2014년 10월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by