Effacer les filtres
Effacer les filtres

Fix the function hlp

9 vues (au cours des 30 derniers jours)
Ainars Cernavskis
Ainars Cernavskis le 26 Jan 2021
Commenté : Rena Berman le 27 Nov 2023
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 commentaires
Sam Chak
Sam Chak le 23 Nov 2023
The original question may be beneficial for people who wish to learn how to create special square matrices.
Rena Berman
Rena Berman le 27 Nov 2023
(Answers Dev) Restored edit

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 26 Jan 2021
Modifié(e) : Jan le 26 Jan 2021
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?

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by