need a help using loop

조회 수: 12 (최근 30일)
Dimas Riansa
Dimas Riansa 2016년 11월 30일
댓글: Dimas Riansa 2016년 12월 26일
hello i have this code that i wanted to shorten by using loop but i can't seems to find how
net1 = perceptron;
net1 = train(net1, P, T1);
net2 = perceptron;
net2 = train(net2, P, T2);
net3 = perceptron;
net3 = train(net3, P, T3);
net4 = perceptron;
net4 = train(net4, P, T4);
net5 = perceptron;
net5 = train(net5, P, T5);
when i tried using simple
for X = 1 : 5;
netX = perceptron;
netX = train(netX, P, TX);
end
it will show that T is still an undefined function or variable thank you.

채택된 답변

James Tursa
James Tursa 2016년 11월 30일
편집: James Tursa 2016년 11월 30일
You have learned the hard way one of the first lessons of good programming practice ... don't create a bunch of variables with trailing numbers like T1, T2, T2, etc because it becomes very hard to use them in downstream programming. You are forced to use eval() and the like to get things done, which further obfuscates your code. See this link for good alternatives (like cell arrays):
  댓글 수: 1
Dimas Riansa
Dimas Riansa 2016년 12월 26일
whoops i forgot i asked this a while ago. yeah, i kinda figured that out after reading few articles. thank you for the answer

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

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by