What is this code supposed to do? I must admit I don't understand it. Anyway, what I see is, that fixdof will be overwritten in each loop iteration. Most likely you don't want that. So you need to use an array here, too (just as you do with x).
If I get your question right, you run your code multiple times and you enter different values for nf each time. In case nf decreases, some x won't be overwritten. Suppose nf is 4 the first time and nm is 0 and ndof is 1. x will be a 1x4 array. Now you change nf to 3, x will remain a 1x4 array and the fourth value will simply remain as it is. You know how many x you need ((nf+nm)*ndof), so just preallocate it with
and the array will have the correct size.
You write you want the matrix to change with updated nf. You don't give the code where matrix is defined, so we cannot comment on that issue.