need help to make program recognize users inputs and associate values of a matrix to that users input
Info
This question is closed. Reopen it to edit or answer.
Show older comments
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 Comments
Image Analyst
on 24 Feb 2013
But you said in your duplicate question that you didn't need help with that first part and only needed help with the second part. Do you really need us to do all 3 parts now?
stephen
on 24 Feb 2013
Image Analyst
on 24 Feb 2013
Well what's the difference between than and this then? I thought it was that you wanted #3 in that question and want #1 in this question. Is there, in fact, any difference in the questions?
stephen
on 24 Feb 2013
Image Analyst
on 24 Feb 2013
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.
Answers (1)
Shaun VanWeelden
on 24 Feb 2013
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.
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!