How to make an index of the points of a vector that can then be used in a matrix
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
This is the function I have generated: function [Points, Elements] = make1DGrid(Nel,L) %L (Lenght of domain) %Nel (Number of elements)
Points = linspace(0,L,Nel)
Elements = [Points(1:end-1);Points(2:end)] end
my function produces: Points = [0 0.33 0.66 1] Elements = [0 0.33; 0.33 0.66; 0.66 1]
But instead of creating a matrix (Elements) where the coordinates of the points are used I need to create a matrix where the index of the points are used i.e for Nel=3, and L=1 Points = [0 0.33 0.66 1] Elements = [1 2; 2 3; 3 4]
1 comentario
Respuestas (1)
Jan
el 30 de Sept. de 2017
Editada: Jan
el 30 de Sept. de 2017
If you need the indices instead of the values, simply use the indices instead of the values :-)
function [Points, Elements] = make1DGrid(Nel,L)
Points = linspace(0, L, Nel);
Elements = [1:Nel-1; 2:Nel].'; % Instead of: [Points(1:end-1); Points(2:end)]
end
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices 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!