Stopping a chart at a certain value.
古いコメントを表示
%For example
%Lets say I made a program for finding radiation decay in a box of some sort. The half life for the radioactive element is every 3 days, and I have to track it until it reaches just before 1/10th of the given safe exposure value of .466.
%So, I simple create and while loop that halves the input, and adds 3 (days) to the output on the chart?
%The example given, with lets say a input value of 150:, It displays:
%Day | Radiation(Status)
%0 150(Unsafe)
%3 75(Unsafe)
%6 37.5(Unsafe)
%9 18.75(Unsafe)
%12 9.375(Unsafe)
%15 4.6875(Unsafe)
%18 2.3438(Unsafe)
%21 1.1719(Unsafe)
%24 0.58594(Unsafe)
%27 0.29297(Safe)
%30 0.14648(Safe)
%33 0.073242(Safe)
%How do I get my code to stop the chart when the radiation level reaches just BEFORE 1/10 of a value (.466) like in this case? My code only displays the ending value, and that is at 36 days, which is incorrect according to this example.
%What I have so far:
% 1. Prompt for Input Data
x=input('Enter ammount of radiation exposure:');
y=0;
while x>(.466/10)*2;
if x>=(.466/10);
x=x/2;
y=y+3;
a=('Unsafe')
m=x
n=y
end
end
a=('Safe')
disp(['Days ', num2str(n), ' Radiation Level = ', num2str(m) , num2str(a)])
%Do I need to create some kind of matrix instead to display and track the half life every 3 days?
%Sorry if I am being a bit unclear.
2 件のコメント
Walter Roberson
2012 年 3 月 1 日
Note: the "if" statement within the "while" is not doing anything useful in that code. You know the condition is true or else the "while" would have stopped already.
Ben
2012 年 3 月 1 日
採用された回答
その他の回答 (1 件)
Walter Roberson
2012 年 3 月 1 日
Assuming you will be continuing with dividing by 2, change your condition to
while x > (.466/10)*2
カテゴリ
ヘルプ センター および File Exchange で Descriptive Statistics and Visualization についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!