MATLAB Answers

Distinguishing matrices in for loops

1 view (last 30 days)
I want to distinguish matrices in a for loop.
The following does not work:
for n=1:5
S{n}=(1./(1 + exp(1).^(-1*S{n})))
Can somebody help me?


David Goodmanson
David Goodmanson on 11 Jul 2017
Hi Oddur, your main problem is that you are setting S{n} to the same value every time at the beginning of the for loop, so the S{n+1} = S{n}*T statement at the end gets killed off and every S comes out the same. You need go get rid of the first statement and put an initial condition for S{1} outside the loop.
KSSV on 12 Jul 2017
You can proceed like this:
T=[0,1,-0.1,0.8,0;0,0,0,1,0;-0.2,-1,0,-0.2,0;0,0,0,0,0;0.2,0.5,-0.5,-0.2,0] ;
S0=[1,1,1,1,1] ;
S = zeros(5,length(T)) ;
for n=1:5
S(n,:)=(1./(1 + exp(1).^(-1*S0*T)))*T ;
What you think is not working?
David Goodmanson
David Goodmanson on 12 Jul 2017
Again, this gives identical values for all rows of S, and I think an iterative process may be intended.

Sign in to comment.

Accepted Answer

Oddur Bjarnason
Oddur Bjarnason on 12 Jul 2017
Edited: Oddur Bjarnason on 12 Jul 2017
Combining the suggestions of David and KSSV I believe that I have found a solution to my problem. I have been trying to write a simple script for computing a Fuzzy-Logic Cognitive Map. The script is as follows:
T=[0,1,-0.1,0.8,0;0,0,0,1,0;-0.2,-1,0,-0.2,0;0,0,0,0,0;0.2,0.5,-0.5,-0.2,0] ;
S0=[1,1,1,1,1] ;
S1=zeros(5,length(T)) ;
S2=zeros(5,length(T)) ;
for n=1:5
S2(n,:)=(1./(1 + exp(1).^(-1*S1(n,:))))
Thank you both..


Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by