Matlab string size to asterisks?

5 views (last 30 days)
Laura
Laura on 11 Oct 2013
Edited: Sean de Wolski on 11 Oct 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

Accepted Answer

Sean de Wolski
Sean de Wolski on 11 Oct 2013
Edited: Sean de Wolski on 11 Oct 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

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!