# How to use a matrix element to define a changing variable

5 Ansichten (letzte 30 Tage)
Kitt am 16 Apr. 2024
Kommentiert: Kitt am 17 Apr. 2024
So I'm writing a stochastic dynamic program on decision-making based on two informational states about 2 patches to forage in. So the observer can watch a demonstrator and update an informational state on the quality of a patch. The probability of going to patch 1, p, is based on the difference between the info state of patch 1 and info state of patch 2, which changes with every time step. How do I make sure that it's calling the right numbers to compare?
The probability of going to a patch is dependent on an element in a matrix that I've made (i.e. info on patch 1<patch 2 go to patch 1 with 10%prob, info on patch 1>patch 2 go to patch 1 with 90%prob, info on patch 1=patch 2 go to patch 1 with 50%prob)
I have a matrix full of the differences between all possible values and I'm trying to use a specific element of the matrix to give this 'p' variable a value. I'm basically trying to write "if the element of matrix M, depending on the current value of z and y (that are modified by an equation), is greater than 0, then p = 0.9"
Does this make sense? p is dependent on the matrix element, but the matrix element depends on the specific fitness equation chunk it's being used for
for tt=19:-1:1
for j=1:15
for k=1:15
for i=info
if M(j,k)>0
p(j,k)==0.9;
elseif M(j,k)<0
p(j,k)==0.1;
elseif M(j,k)==0
p(j,k)==0.5;
end
Fd(i,j,k)= b*(...
m1*(...
p(y(j),z1(k))*(n1*Fd(xp(:,i),zp(j),y(k),tt+1) + (1-n1)*Fd(xpp(:,i),zpp(j),y(k),tt+1))+...
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Catalytic am 17 Apr. 2024
Bearbeitet: Catalytic am 17 Apr. 2024
Use a single '=' sign for assigning values, not '=='.
if M(j,k)>0
p(j,k)=0.9;
elseif M(j,k)<0
p(j,k)=0.1;
elseif M(j,k)==0
p(j,k)=0.5;
end
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Kitt am 17 Apr. 2024
Thank you! I've definitely messed that up before. Onto the next error!

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Polygons finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by