I have created a for loop that uses the last variable generated in the first step in order to run. I need the values of the last variable to be displayed in a row matrix so I can plot a graph. Can you help?

Suppose I am running this- x=3 for Y=1:4 x=x+1 end I need the value of x to be displayed like 3 4 5 6 7. But if I try doing x(x)=x+1 in the loop, it not giving any result. What do I do?

 Accepted Answer

x(1) = 3;
x(5) = 0;
for y=2:5
x(y)=x(y-1)+1 ;
end

2 Comments

Thank you. But that was an example that I used and my actual loop looks like this for t=1:3 Nl=e*nt; %nt=no. of eggs %for HL mean=x1*(1-(1/(x2+exp(-x3*Nl+hf))))%of the body size assumed after larval stage sd=0.45 %standard deviation R=normrnd(mean,sd,1,Nl)%chooses random numbers from the curve of normal distribution around mean body size B=R(R>=mc)%chooses those flies with body size greater than mc N1=numel(B)%counts the no. of adult flies c=mod(N1,2)%finds whether N1 is even or odd if c==1 %finds no. of females females=(N1-1)/2 else females=N1/2 end si=randsample(B,1)%selects a particular body size S=log(x4+x5*si)%fractional contribution of body size towards fecundity Na=Nl-1 %adult population density experienced by a fly G=1/(1+d*Na)%effect of adult density on female fecundity fecundity=ly*S*G %of one fly eggs=fecundity*females %probable no. of eggs nt=floor(eggs) end All the variables have been defined including the first nt.I want to plot a graph of nt vs. t and I am unable to do so. Can you help?
nt = zeros(1,3);
nt(1) = 5; % HERE, please enter your initial volume
sd=0.45;%standard deviation
for t=2:3
Nl=e*nt(t-1); %nt=no. of eggs
%for HL
mean1=x1*(1-(1/(x2+exp(-x3*Nl+hf))));%of the body
%assumed after larval stage
R=normrnd(mean1,sd,1,Nl);%chooses random numbers from the curve of normal
%distribution around mean body size
B=R(R>=mc);%chooses those flies with body size greater than mc
N1=numel(B);%counts the no. of adult flies
c=mod(N1,2);%finds whether N1 is even or odd
females=(N1-(mod(N1,2) == 1))/2;
si=randsample(B,1)%selects a particular body size
S=log(x4+x5*si)%fractional contribution of body size towards fecundity
Na=Nl-1; %adult population density experienced by a fly
G=1/(1+d*Na);%effect of adult density on female fecundity
fecundity=ly*S*G; %of one fly
eggs=fecundity*females; %probable no. of eggs
nt(t)=floor(eggs);
end

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!