Our sample set is given as {-1,1.5,2,2.5}.
b = from "outcome" value to outcome(index100) value.
There is a problem that outcome(1) cannot be equal to a matrix value. Hence I set "outcome" (without (1)index) equal to the matrix value. But unfortunately, yet > or < operators cannot work with a matrix value, And I don't know how to work with rand function. In fact, I like when a negative value is randomly chosen then the next time double of it being selected, but when a positive random value is chosen it don't get doubled. I give you the code:
sample={-1,1.5,2,2.5};
for i=1:100
z=i;
outcome=randsample(sample,1);
if outcome>0
z=1;
else
z=i;
outcome(z)=(2^z)*outcome;
end;
if i==1
result=outcome;
end;
end;
b = outcome:outcome(100);
result = sum(b,"all");
plot result;
end
Any vision for helping me?
a,bandzvariables are supposed to do. Use descriptive names for your variables. It would also be a good idea that for a smaller range (eg:for i=1:5) you provide what is the result you expect, so we can better understand what are you trying to do.sample=[-1,1.5,2,2.5];with square bracketsresultto be a single value, sum of alloutcome? Becauseoutcome:outcome(100)is an array with all integer values in betweenoutcome(1)andoutcome(100), if both of them are integers, the other values inoutcomewould be ignored. I think you meant to dooutcome(1:100). What isplot resultmeant to do?outcome(i)=randsample(sample,1);would work ifsampleis defined as a numeric array as @wolfie suggested.