Fix the function hlp

조회 수: 6 (최근 30일)
Ainars Cernavskis
Ainars Cernavskis 2021년 1월 26일
댓글: Rena Berman 2023년 11월 27일
i was told to write funciton for this: but it keeps saying something is wrong but i dont know what is wrong with it .
function [ arr ] =special_matrix( n )
if n>2
for i = 1:n
for j = 1:n
if mod(j,3)==0
arr(i,j)}=((i-1)*n+j}^j;
else
arr(i,j)={i-1}*n+j;
end
end
end
else
disp('Error; n must be greater than i')
end
end
  댓글 수: 3
Sam Chak
Sam Chak 2023년 11월 23일
The original question may be beneficial for people who wish to learn how to create special square matrices.
Rena Berman
Rena Berman 2023년 11월 27일
(Answers Dev) Restored edit

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2021년 1월 26일
편집: Jan 2021년 1월 26일
By the way, this can be done in one line:
arr = reshape(1:n^2, n, n).' .^ ((1:n) .^ rem(0:n-1, 2))
Have fun with analyzing, how this works.
Is there a shorter solution?

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by