How do I do this? I NEED HELP!!!
信息
此问题已关闭。 请重新打开它进行编辑或回答。
显示 更早的评论
Create a MATLAB script that asks the user repeatedly for a string, and it verifies if the string has its characters ordered based on their numerical value. If the characters are ordered in ascending order then the output will be a message like “Your string is ordered” otherwise the message will be something like “Not in order!”. The program will stop when the user enters the character 0, otherwise it will keep asking for a new string. Create your own functions if needed. This is how the interactive input/output will look like:
Enter your string: "adhkp"
Your string "adhkp" has its characters ordered!
Enter your string: "3gtAq"
Your string "3gtAq" has its characters not ordered!
Enter your string: ";9Zalpq"
Your string ";9Zalpq" has its characters ordered!
. . .
. . .
Enter your string: "0"
5 个评论
per isakson
2018-11-5
Homework? What have you done so far?
Andrew Anderson
2018-11-5
per isakson
2018-11-5
编辑:per isakson
2018-11-5
I guess you are better helped by doing MATLAB Onramp (free) while you are waiting for an answer here. It's good!
Do you find those exercises trivial?
Andrew Anderson
2018-11-5
per isakson
2018-11-5
Ok, but did you find it trivial? If not it's difficult to help you doing your homework.
回答(1 个)
Star Strider
2018-11-5
0 个投票
You need to determine if the characters are sorted.
(For homework problems, we give hints.)
4 个评论
Andrew Anderson
2018-11-5
John D'Errico
2018-11-5
THINK! Is each element greater than or equal to the previous one? If so, is it in order? So you just need a sequence of comparisons, comparing each to the one that preceded it.
per isakson
2018-11-5
编辑:per isakson
2018-11-5
@John, The text of the assignment is full of double quotes; the user is supposed to give the answer in double quotes, e.g. ";9Zalpq". Doesn't this mean that the task is supposed to be solved with strings? With strings I fail to find a clean way to compare elements. String is "high level" and Matlab provides issorted for the task, "ordered based on their numerical value", (with "numerical" replaced by "unicode").
Walter Roberson
2018-11-5
One of the fundamental properties of string scalars is that you can use {} indexing to get at the character vector. Which you could then process in various ways including diff()
此问题已关闭。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!