Narxnet, Error using struct, Conversion to struct from double is not possible.

In the Matlab UserGuide for Neural Networks Toolbox R2012a (page 3-25), there is an example of a Dynamics Network with the following code:
load magdata
[u,us] = mapminmax(u);
[y,ys] = mapminmax(y);
y = con2seq(y);
u = con2seq(u);
d1 = [1:2];
d2 = [1:2];
narx_net = narxnet(d1,d2,10);
narx_net.divideFcn = '';
narx_net.trainParam.min_grad = 1e-10;
[p,Pi,Ai,t] = preparets(narx_net,u,{},y);
narx_net = train(narx_net,p,t,Pi);
yp = sim(narx_net,p,Pi);
e = cell2mat(yp)-cell2mat(t);
plot(e);
But when I use the code above I get the following error message:
Error using struct Conversion to struct from double is not possible.
However when I use:
narx_net = narxnet(1:2,1:2,10);
Instead of:
d1 = [1:2];
d2 = [1:2];
narx_net = narxnet(d1,d2,10);
The program runs okay.
Then when I try to run the same code but with my own input and output data. So I define u and y myself, I got the same error message again.
Even more strange when I then try to run the original code (see below) then I also get the error message, while previous the code run fine??? When I restart Matlab, the code below works fine again???
load magdata
[u,us] = mapminmax(u);
[y,ys] = mapminmax(y);
y = con2seq(y);
u = con2seq(u);
narx_net = narxnet(1:2,1:2,10);
narx_net.divideFcn = '';
narx_net.trainParam.min_grad = 1e-10;
[p,Pi,Ai,t] = preparets(narx_net,u,{},y);
narx_net = train(narx_net,p,t,Pi);
yp = sim(narx_net,p,Pi);
e = cell2mat(yp)-cell2mat(t);
plot(e);
Hopefully someone can help me with this mystery. Many thanks

 채택된 답변

Sean de Wolski
Sean de Wolski 2012년 8월 10일

0 개 추천

If you highlight that selection in the help and right click "Evaluate Selection" do you get the same error?
I am guessing you have a variable/script/function shadowing one of the above since I do not get the error copying what you have above.

댓글 수: 4

Sean,
Your are right when I use "Evaluate Selection" I do not get the same error. In fact I get no error.
What is your suggestion to solve this ??
1. Try the initial command
clear all; clc
2. Where is this "Evaluate Selection" command?
To use ‘Evaluate Selection’, highlight a section of code (in the MATLAB Editor), then right-click and select the first entry in the menu that appears.
It is best NOT to use the same variable name on both sides of an equation. Try using 3 variables for u and y in
[u,us] = mapminmax(u);
[y,ys] = mapminmax(y);
y = con2seq(y);
u = con2seq(u);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2012년 8월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by