Search code examples
matlabfinite-element-analysis

Rearranging a vector in matlab


I'm writing a code for adaptive finite element method in 1d. I have an interval let say [0,1] and in first iteration I have a mesh, x=0:.25:1 and in second iteration I would like to divide the second and last segment in 3 and 5 segments. So the updated vector, x has 11 nodes. This process will be repeated over and over with different segments. I am really confused how can I update the vector x?


Solution

  • Let's say your vector x has n elements. And you want to update the i-th segment and divide it into k parts. then:

    x = [x(1:i-1), x(i):((x(i+1) - x(i))/k):x(i+1), x(i+2:n)];