Matlab string size to asterisks?
조회 수: 3 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Sean de Wolski
2013년 10월 11일
편집: Sean de Wolski
2013년 10월 11일
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
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!