Index loop into matrix

2 visualizaciones (últimos 30 días)
Simon Kibsgaard
Simon Kibsgaard el 2 de Dic. de 2020
Comentada: Simon Kibsgaard el 2 de Dic. de 2020
Hi
Im very new to MatLab.
Im trying to get this loop to produce a 10x3 matrix and not 10 sepperate answers.
triCoord=10x9
ntri = 10
qTop = zeros(ntri,3)
for n=1:ntri
qTop =[]
qTop(n,:) = [qTop
mean(triCoord(n,[1 4 7])),mean(triCoord(n,[2 5 8])),mean(triCoord(n,[3 6 9]))]
end
qTop

Respuesta aceptada

VBBV
VBBV el 2 de Dic. de 2020
triCoord= zeros(10,9);
ntri = 10
qTop = zeros(ntri,3);
for n=1:ntri
qTop(n,:) = [mean(triCoord(n,[1 4 7])),mean(triCoord(n,[2 5 8])),mean(triCoord(n,[3 6 9]))];
end
qTop
  1 comentario
Simon Kibsgaard
Simon Kibsgaard el 2 de Dic. de 2020
Thanks v much, thats what i needed

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing 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!

Translated by