How can I sort data in a loop with an if selection structure?
Show older comments
Say if I have a vector of numbers grades = [84;62;91;85;73;69;44;90;82] and I want to sort them like grades, A being 90-100, B being 80-89, C being 70-79, D being 60-69, and F below 60. I want to use a loop with an if selection structure to sort them. But when I run my code only my F values show up with a column vector of zeros and 1's being in place of the values that are true for the F grades. Any suggestions on how to correctly do this?
4 Comments
Mikhail
on 21 Oct 2014
Please specify output format. Write it for your example
Michael Toney
on 21 Oct 2014
Amit Varshney
on 21 Oct 2014
You do need the 'if' and 'elseif' statements. Try the following
A2 = grades(find(grades >= 93))
A_m2 = grades(find(grades >= 90 & grades < 93))
ans so on..
Michael Toney
on 21 Oct 2014
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!