Have you checked if Nx1 is not already existing before the for loop? It might be that it already exists and that it is a scalar. A hint could be to clear the workspace at the beginning of the code. Anyway, you can trigger "Pause on error" (click on the small arrow under the "Run" button). It will pause the execution right before the error, then launch the code and when it stops, look at the list of variable to check if Nx1 is not just a scalar.