How do I do this? I NEED HELP!!!
Informazioni
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Mostra commenti meno recenti
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 Commenti
per isakson
il 5 Nov 2018
Homework? What have you done so far?
Andrew Anderson
il 5 Nov 2018
per isakson
il 5 Nov 2018
Modificato: per isakson
il 5 Nov 2018
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
il 5 Nov 2018
per isakson
il 5 Nov 2018
Ok, but did you find it trivial? If not it's difficult to help you doing your homework.
Risposte (1)
Star Strider
il 5 Nov 2018
0 voti
You need to determine if the characters are sorted.
(For homework problems, we give hints.)
4 Commenti
Andrew Anderson
il 5 Nov 2018
John D'Errico
il 5 Nov 2018
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
il 5 Nov 2018
Modificato: per isakson
il 5 Nov 2018
@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
il 5 Nov 2018
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()
Questa domanda è chiusa.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!