problem using hold on in a for loop
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
For my project, I am calculating the half-life of an organism based on radioactive decay. My code is below. The problem I am experiencing is that he figure only has one point plotted. If someone could explain how to fix this so my entire function would be plotted, that would be greatly appreciated.
function Project
clc, clear
P=menu ('Please choose the element', 'Pm-145', 'Po-209', 'Ra-226', 'Ac-227', 'Am-243', 'Bk-247', 'Cf-251', 'C-14');
switch P %P=element found in sample through AMS
case 1 % Promethium-145
t=17.4;
case 2 % Polonium-209
t=102;
case 3 % Radium-226
t=1600;
case 4 % Actinium-227
t=21.77;
case 5 % Americium-243
t=7370;
case 6 % Berkelium-247
t=1380;
case 7 % Californium-251
t=898;
case 8 % Carbon-14
t=5730;
end
N=input ('Please enter the remaining percentage of substance: \n');
while N<=0 || N>=100 %N=percentage of element found through AMS
fprintf ('Incorrect input. Please try again. \n');
N=input ('Please enter the remaining percentage of substance: \n');
end
clc
age=(((log((N)/(100)))/(-0.693))*t);
fprintf ('The age of your organism is shown below: \n');
fprintf (' %s years',age);
n=length(N);
for i=1:n
plot(age(i), N(i), '*', 'MarkerSiz', 10)
xlim([0 inf])
ylim([0 100])
pause(.01)
hold all
xlabel(strcat('Years passed = ', num2str(age(i))))
ylabel(strcat('Percentage remaining =', num2str(N(i))))
title ('Radioactice Decay')
grid on
end
end
Thanks!
6 Kommentare
Antworten (1)
the cyclist
am 16 Jul. 2019
Your variable N is a single value -- a scalar. (It is an array of length 1.) You then define n to be the length of that array. So n = 1.
Then, you plot in a for loop that goes from 1 to n. But that's from 1 to 1. So, you get one point.
4 Kommentare
Siehe auch
Kategorien
Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!