How do I fix the array error?
显示 更早的评论
Hi,
I am required to create a script where the user can input a number of years to project the population of turtles and then have the data displayed for them in separate vectors and a plot.
My script so far allows me to look at data up to 2 years, but anything over that and I get an array error... Any help would be appreciated!
NumberOfYears = input ('Please enter the number of years you would like to project the population of Loggerhead Turtles for: ');
while NumberOfYears <= 0
NumberOfYears = input ('Error! The number of years must be larger than zero. Please enter the number of years you would like to project the population of Loggerhead Turtles for: ');
end
%Initial populations of turtles at Year 0.
Hatchling = 1445570;
Youth = 5536790;
BreedingAdult = 17640;
ProjectedTime = 1:NumberOfYears;
HatchVec = zeros(1,length(ProjectedTime));
for t = ProjectedTime
HatchVec = Hatchling - (Hatchling .* 0.675) - (Hatchling .* 0.325) + (BreedingAdult .* 77.4);
HatchVec = [Hatchling HatchVec];
end
fprintf ('The projected population of Hatchlings per year is: \n')
disp(HatchVec)
YouthVec = zeros(1,length(ProjectedTime));
for t = ProjectedTime
YouthVec = (Hatchling .* 0.675) + (Youth .* 0.769) - (Youth .* 0.230);
YouthVec = [Youth YouthVec];
end
fprintf ('The projected population of Youth per year is: \n')
disp(YouthVec)
AdultVec = zeros(1,length(ProjectedTime));
for t = ProjectedTime
AdultVec = BreedingAdult - (BreedingAdult .* 0.809) + (Youth .* 0.000434);
AdultVec = [BreedingAdult AdultVec];
end
fprintf ('The projected population of Breeding Adults per year is: \n')
disp(AdultVec)
plot(ProjectedTime, HatchVec)
xlabel ('Projected Years')
ylabel ('Number of Loggerhead Turtles')
title ('Projected Population of Loggerhead Turtles')
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Tracking and Sensor Fusion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!