Matlab string size to asterisks?

3 visualizzazioni (ultimi 30 giorni)
Laura
Laura il 11 Ott 2013
Modificato: Sean de Wolski il 11 Ott 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

Risposta accettata

Sean de Wolski
Sean de Wolski il 11 Ott 2013
Modificato: Sean de Wolski il 11 Ott 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

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by