MATLAB: How to modify values in an array at a certain point inside a loop

changing of values inside loop

I have formed this simple code
clc
clear all
a=1.4
for i=1:10 %Here i represents years
A(:,:,i)=a; %For storing the values in 3D matrix
a = a * 0.9;
end
The answer I am getting is
val(:,:,1) =
1.4000
val(:,:,2) =
1.2600
val(:,:,3) =
1.1340
val(:,:,4) =
1.0206
val(:,:,5) =
0.9185
val(:,:,6) =
0.8267
val(:,:,7) =
0.7440
val(:,:,8) =
0.6696
val(:,:,9) =
0.6027
val(:,:,10) =
0.5424
I want to modify my code such that when the value of 'a' becomes less than a<0.6*1.4 so for that year 'a' should be 1.4 again.Like in this case in year 6 the value is 0.8267 which is less than 0.6*1.4 so val(:,:,6) should become 1.4 and then again the 'a' will be calculated as per defined equation.I mean I want my answer like this and also I want the year in which the value becomes 1.4 again like here in this case the year is 6.How can I modify my code in order to get this answer?Kindly help me
Desired Answer:
val(:,:,1) =
1.4000
val(:,:,2) =
1.2600
val(:,:,3) =
1.1340
val(:,:,4) =
1.0206
val(:,:,5) =
0.9185
val(:,:,6) =
1.4000
val(:,:,7) =
1.2600
val(:,:,8) =
1.1340
val(:,:,9) =
1.0206
val(:,:,10) =
0.9185

Best Answer

Just add if condition inside your for loop
clc
clear all
a=1.4
for i=1:10 %Here i represents years
A(:,:,i)=a; %For storing the values in 3D matrix
a = a * 0.9;
if a < 1.4*0.6
a = 1.4;
end
end