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 comentarios

per isakson
per isakson el 5 de Nov. de 2018
Homework? What have you done so far?
Andrew Anderson
Andrew Anderson el 5 de Nov. de 2018
Yes. I'm completely lost on how to answer my questions.
per isakson
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
Andrew Anderson el 5 de Nov. de 2018
Yeah... there not super helpful. I appreciate having it as a future source. I'm in a rush and I'm really lost
per isakson
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
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
Andrew Anderson el 5 de Nov. de 2018
I know I have to convert the characters to their corresponding numerical values, but how do I compare down the string to ensure the string is in order?
John D'Errico
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
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
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.

Preguntada:

el 5 de Nov. de 2018

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by