Q:

Function fitting neural network in for loop in MATLAB

I'm using MATLAB R2014a version. 
I have ten clusters of X, and y data. 
I want to fit these 10 corresponding data model by using a neural network tool in MATLAB.  And I want to save 10 different models in somewhere. 
For each cluster, I need to design an implementation to determine the correct number of hidden layers.  And I will save each model into an array or something like that.  And then continue for the 2nd cluster. 
For this aim, I have developed this algorithm:
for q = 1:z                             % number of clusters
    mdl  = fitnet( 10 );
    mdl  = train( mdl, X( classes == q ), y( classes == q ) );

    view( mdl );

    yy   = net( X( classes == q ) );
    perf = perform( net, yy, y( classes == q ) );

    model( q ).mdl = mdl;
    clear mdl;
end

When I run this code, I get this error:
Error using view (line 67)
Invalid input arguments

Error in Main (line 97)
    view(mdl);

How can I fix the problem? 
Thanks,

A:

Unlike mentioned in the comments view() is the right function to choose here because it has been overloaded to also show a sketch of a neural network (see here: http://www.mathworks.com/help/nnet/ref/view.html). 
So, the problem obviously is not view() itself, but your mdl-network which means you should:

go there with a debugger and check if it really is a neural network and if it contains values
check those values because X and y might not be the vectors you want (which you should also check)

...and/or post more information about what's going on in your code.