How to use a matrix element to define a changing variable

7 次查看(过去 30 天)
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))+...

采纳的回答

Catalytic
Catalytic 2024-4-17
编辑:Catalytic 2024-4-17
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Polygons 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by