How to fill a 3D Array using a for loop
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Pedro Pires
el 17 de Nov. de 2016
Comentada: Pedro Pires
el 18 de Nov. de 2016
Hi, I've been having a problem filling a matrix. I need to fill it using a "for" loop, but the equations for each element is different. I hope the example can explain better what I pretend to achieve. Hope someone can help. Thanks.
for i=1:5
k(i,1,1)=2*x(i);
k(i,1,2)=9*y(i);
k(i,2,1)=-2*x(i);
k(i,2,2)=-2*y(i);
end
0 comentarios
Respuesta aceptada
KSSV
el 18 de Nov. de 2016
x = rand(5,1) ;
y = rand(5,1) ;
k = zeros(2,2,2) ;
for i=1:5
k(i,1,1)=2*x(i);
k(i,1,2)=9*y(i);
k(i,2,1)=-2*x(i);
k(i,2,2)=-2*y(i);
end
What problem you face? Code is fine.
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!