You do not need to know the value of n at the beginning, but depending on what you want to do with your matrix, you may or may not need to know the value of n at some point later on.
For example, in the following code, the size of the variable x does not need to be known in advance, but it does need to be known at the time you choose to call this function:
function y = timestwo(x)
y = 2*x;
end
The only thing that is known in advance is that the size of y will be the same as the size of x, whatever that is at runtime. In addition, the data class and complexity of y will also be the same as x. But again, until you call this function, there is no way to know nor is there any need to know any of these characteristics of the variables x and y.
Can you please be more specific about what you would like to do, what you have tried so far, what is not working in what you have tried, and what you would like us to help you with?
Thanks!
Rick