How to make Subscript indices real positive integers or logicals?

조회 수: 2 (최근 30일)
Nick
Nick 2021년 5월 9일
편집: Nick 2021년 5월 14일
I wrote this code in order to create a neural network to approach the function f(x,y,z)=z^2 + x^3 -2xcos(yz+4) within [-1,1].
clc; clear;
x = -1:.01:1;
y = -1:.01:1;
z = -1:.01:1;
f=z.*z + x.*x.*x -2*x.*cos(y.*z +4);
Px=x; Py=y; Pz=z; P={Px;Py;Pz}; T=f;
net=newff([-1 1], [30,30,1], {'tansig','tansig','purelin'},'traingd');
net.trainParam.show = 200;
net.trainParam.lr = 0.01;
net.trainParam.epochs =5000;
net.trainParam.goal = 1e-5;
net.numinputs = 3;
trained = train(net,P, T);
N = 100;
Pxtest = 4*rand(1,N);
Pytest = 4*rand(1,N);
Pztest = 4*rand(1,N);
Ptest=[Pxtest;Pytest;Pztest];
fTest = f(Ptest);
testing= sim(trained,Ptest);
plot(Ptest,atest,'ro', Ptest,fTest,'b*'); grid;
legend('predicted value','actual value')
When I run it, I get the Error :
Subscript indices must either be real positive integers or logicals.
Error in approach_function(line 26)
fTest = f(Ptest);
How can I make that right?
  댓글 수: 5
Rik
Rik 2021년 5월 12일
편집: Rik 2021년 5월 12일
Why do you want to delete the question? If you want private help you should hire a consultant instead of posting on a public forum.
Just so others can still read it after you attempt to delete it:
I wrote this code in order to create a neural network to approach the function f(x,y,z)=z^2 + x^3 -2xcos(yz+4) within [-1,1].
clc; clear;
x = -1:.01:1;
y = -1:.01:1;
z = -1:.01:1;
f=z.*z + x.*x.*x -2*x.*cos(y.*z +4);
Px=x; Py=y; Pz=z; P={Px;Py;Pz}; T=f;
net=newff([-1 1], [30,30,1], {'tansig','tansig','purelin'},'traingd');
net.trainParam.show = 50;
net.trainParam.lr = 0.01;
net.trainParam.epochs =1000;
net.trainParam.goal = 1e-5;
net.numinputs = 3;
%Train
net1 = train(net,P, T);
N = 100;
Pxtest = 4*rand(1,N);
Pytest = 4*rand(1,N);
Pztest = 4*rand(1,N);
Ptest=[Pxtest;Pytest;Pztest];
fTest = f(Ptest);
atest= sim(net1,Ptest);
mse = sum((fTest-atest).^2)/N;
fprintf('Mean square Error = %.4f\n', mse)
% Plot
plot(P,T,'r--',Ptest,atest,'ro', Ptest,fTest,'b*'); grid;
legend('Function','predicted value','actual value')
When I run it, I get the Error :
Subscript indices must either be real positive integers or logicals.
Error in approach_function(line 26)
fTest = f(Ptest);
How can I make that right?
Rik
Rik 2021년 5월 12일
Why do you want to delete the question?

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

답변 (1개)

Image Analyst
Image Analyst 2021년 5월 9일

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by