How to store user-generated text within a loop?
2 次查看(过去 30 天)
显示 更早的评论
How would i write this code to run in a loop?
p='What is the name of a eng 1315 student? ';
n1=input(p,'s');
n2=input(p,'s');
n3=input(p,'s');
n4=input(p,'s');
n5=input(p,'s');
my objective involves importing data (which will be set of grades) from an excel doc then sorting and calculating the data for the entered students to be displayed in order from highest average to lowest. I would like to shorten this portion because extra credit will be given to the student with the shortest code. If running this in a loop is not possible I am open for any other suggestions to shorten this portion. Thanks.
0 个评论
采纳的回答
Evan
2014-11-13
In order to store multiple strings, likely of different lengths, you will need to use a cell array. See here for help on writing data to a cell array.
It is certainly possible to do this in a loop. The input function will pause execution of the loop until the user enters data, and then it will move onto the next iteration.
Note that giving exact solutions to classwork is discouraged on this site, but users here will be very happy to help you with tips and partial solutions.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!