Compare letters in a string.

3 visualizaciones (últimos 30 días)
Giuseppe
Giuseppe el 2 de Abr. de 2014
Respondida: Walter Roberson el 2 de Abr. de 2014
say i have the string hello for eaxample. I want to compare if the first element in this string equalls the last, if the second equalls the second last, if the third equalls the third last ect untill there is nothng left to compare. I know I could flip it but i am required to do it in this manner. I would like to then display the result as a logical value in a matrix. Would I do it like this.
while loop (until there is enough to compare)
if element(1) equalls endelement
(first value in answer matrix equalls 1)
else
(first value in answer matrix equalls 0)
Sorry for the poor structure I just cant figure out how to code this.

Respuestas (1)

Walter Roberson
Walter Roberson el 2 de Abr. de 2014
Hint: if an array is (for example) 14 elements long, then what is the index of the second element, and what is the index of the second-last element? What is the index of the third element, and what is the index of the third-last element?

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by