Borrar filtros
Borrar filtros

Create aa difficult matrix in a loop

6 visualizaciones (últimos 30 días)
Tim
Tim el 4 de En. de 2019
Editada: Jan el 4 de En. de 2019
Hey all,
in general I dont have much problems creating a matrix with a loop, but I cant see the pattern here.
If loop is not the right answer here, maybe you could give me a hint for something else?
Thx !
  2 comentarios
Jan
Jan el 4 de En. de 2019
Editada: Jan el 4 de En. de 2019
There is no "if loop" in any programming language I know. You showed 3 different matrices. There is an infinite number of methods to create these 3 matrices with a certain number of input arguments. So what is the actual definition and what are the parameters for the 3 examples? There are some white and some light blue cells. Please do not let the readers guess the details.
Tim
Tim el 4 de En. de 2019
Oh, I am sorry. I will edit right away.

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 4 de En. de 2019
Editada: Jan el 4 de En. de 2019
With some bold guessing:
n = 2;
R = -ones(n+1, n, n+1);
v = 1:n+1;
for k = v
R(v(v ~= k), :, k) = eye(n);
end
R = reshape(R, n+1, n*n+n)

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by