How to use a matrix element to define a changing variable

조회 수: 3 (최근 30일)
Kitt
Kitt 2024년 4월 16일
댓글: Kitt 2024년 4월 17일
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
  댓글 수: 1
Kitt
Kitt 2024년 4월 17일
Thank you! I've definitely messed that up before. Onto the next error!

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

추가 답변 (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