Matlab string size to asterisks?

3 visualizaciones (últimos 30 días)
Laura
Laura el 11 de Oct. de 2013
Editada: Sean de Wolski el 11 de Oct. de 2013
Hi there, I am taking an introduction to MATLAB course and I have been having trouble completing this task: "Write a program to input 2 strings from the user and to print out (i) the concatenation of the two strings with a space between them, (ii) a line of asterisks the same length as the concatenated strings, and (iii) the reversed concatenation. [Hint: use disp and char] and use the work done in Q2(a) above.
For example:
Enter string 1: Mark
Enter string 2: Huckvale
Mark Huckvale
*************
elavkcuH kraM "
I can do part (i), however when it comes to (ii) and (iii) I can't seem to get it. The hint says use char.. but I don't really know how to use it to display asterisks or reverse the string. Any guidance on this would be extremely helpful.
Thanks, Laura

Respuesta aceptada

Sean de Wolski
Sean de Wolski el 11 de Oct. de 2013
Editada: Sean de Wolski el 11 de Oct. de 2013
Here's a hint:
x = 'Friday Rocks'
char(42+zeros(size(x)))
I found the 42 by running:
int8('*')
To reverse a string, look at fliplr.
doc fliplr

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by