Array of neuralnet structs

Hello everyone,
I'm using Matlab2010a and I do in a loop a several neural networks.
Then I'm trying to save all the neural networks, like above:
for k=1:20
clear cfnet1; clear tr;
cfnet1=newcf(P,T,2,{'tansig' 'tansig'});
cfnet1.trainParam.max_fail = 10;
cfnet1.trainParam.showWindow = 0;
[cfnet1,tr] = train(cfnet1,P,T);
TR(k)=tr;
NET(k)=cfnet1;
end
I can save all the 'tr' in an array, but in case of the neuralnet it is not possible.
Generates an error about arrays and not double values.
??? The following error occurred converting from network to double:
Error using ==> double
Conversion to double from network is not possible.
Did someone try it before ? Is it works in latest versions of Matlab ?

 Respuesta aceptada

Sean de Wolski
Sean de Wolski el 22 de Ag. de 2011

3 votos

I think you want TR, NET to be cell arrays or struct arrays?
NET = cell(20,1); %cell arrays
for..
NET{K} = cfnet1
end

Más respuestas (2)

Walter Roberson
Walter Roberson el 22 de Ag. de 2011

0 votos

How exactly are you initializing NET ?
Tiago
Tiago el 22 de Ag. de 2011

0 votos

Walter, I don' t initialize TR, nor NET. Just to put in a loop the TR array workout. Any array is possible, no needing to initialize. I thought that would workout with the networks array, but it didn't.
---
Sean, I want a array. Whatever it is structs array or cell array. I tried this 'NET = cell(20,1)' but didn't work
??? In an assignment A(:) = B, the number of elements in A and B must be the same.
Matlab tries to insert 20 elements once, not one-by-one.
If change the line "NET(k)=cfnet1;" to "NET(k,:)=cfnet1;" another error occurs: ??? Assignment has more non-singleton rhs dimensions than non-singleton subscripts
if 'NET = cell(20)' the errors is: ??? Subscripted assignment dimension mismatch.
---
This case is more clever than we think. The problem is an array of networks. The type neuralnet is network, not struct nor cell. so I think that we need a network array.
Thanks for all, Tiago

3 comentarios

Walter Roberson
Walter Roberson el 22 de Ag. de 2011
Could it be that NET already has a value? Try
clear NET
before the loop.
Sean de Wolski
Sean de Wolski el 22 de Ag. de 2011
I'm using braces, you're using parenthesis!
NET{k} is much different than NET(K)
Tiago
Tiago el 23 de Ag. de 2011
Thanks Sean,
that works fine !
Sorry, I didn't read { } braces instead of ( ) parenthesis

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 22 de Ag. de 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by