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 Exchange에서 Descriptive 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