How do I do this? I NEED HELP!!!
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
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 comentarios
per isakson
el 5 de Nov. de 2018
Homework? What have you done so far?
Andrew Anderson
el 5 de Nov. de 2018
per isakson
el 5 de Nov. de 2018
Editada: per isakson
el 5 de Nov. de 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
el 5 de Nov. de 2018
per isakson
el 5 de Nov. de 2018
Ok, but did you find it trivial? If not it's difficult to help you doing your homework.
Respuestas (1)
Star Strider
el 5 de Nov. de 2018
0 votos
You need to determine if the characters are sorted.
(For homework problems, we give hints.)
4 comentarios
Andrew Anderson
el 5 de Nov. de 2018
John D'Errico
el 5 de Nov. de 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
el 5 de Nov. de 2018
Editada: per isakson
el 5 de Nov. de 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
el 5 de Nov. de 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()
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!