Info
此问题已关闭。 请重新打开它进行编辑或回答。
need help to make program recognize users inputs and associate values of a matrix to that users input
1 次查看(过去 30 天)
显示 更早的评论
im writting a program that measures the average water level at a dam for a period of 8 years and i need to ask the user to input a year that he or she would like to examine, the program needs to recognize if the years a valid option and associate it with that years average water levels and then compare the users input with the year before and after, how do i make the program recognize say if the user inputs the year 2000, the program would know its a valid option and then show the average water levels for that year thats in a matrix.
thank you for your time and consideration.
5 个评论
Image Analyst
2013-2-24
Ok, I was just trying to figure out which one to answer, but now I won't worry about either question. Leaves me time to answer lots of other questions. Good luck though.
回答(1 个)
Shaun VanWeelden
2013-2-24
Hey Stephen,
I did not look at your apparent other question, but to validate the year is very straightforward. I would do something like this:
minYear=1995
maxYear=2005
userYear=input('Enter the year you would like to examine');
while userYear<minYear || userYear>maxYear
fprintf('Please enter a year between %.0f and %.0f\n',minYear,maxYear)
userYear=input('Enter the year you would like to examine');
end
now if you had a lot of years, I would recommend putting them in a 3-D matrix, with each 2-d slice being a year, but since you only have 8, I would recommend just using the switch statement, which would go something like this:
switch userYear
case 1995
do something with 95 matrix
case 1996
do something with 96 matrix
....
end
You could alternatively just use the menu function possibly to select the year.
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!