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
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
Ben 2012 年 3 月 1 日
Understood.

サインインしてコメントする。

 採用された回答

Ben
Ben 2012 年 3 月 2 日

0 投票

Thanks again for the help, I looked back at it and worked out all the kinks, and got it to display correctly now as well. Here is what I was going for:
x=input('Enter ammount of radiation exposure in millirem:');
y=0;
while x > (.466/10)*2;
if x>(.466/10);
x=x/2';
y=y+3';
end
if x>.466;
a=(' (Unsafe)');
else x<.466;
a=(' (Safe)');
end
disp(['Day: ', num2str(y), ' Radiation Level= ', num2str(x), num2str(a)])
end

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 3 月 1 日

1 投票

Assuming you will be continuing with dividing by 2, change your condition to
while x > (.466/10)*2

1 件のコメント

Ben
Ben 2012 年 3 月 1 日
Thank you! That solved the issue with it not stopping at the correct value.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDescriptive Statistics and Visualization についてさらに検索

タグ

質問済み:

Ben
2012 年 3 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by