Hey, I want to make the output return # as many times as a certain string has, and then, change each # with the corresponding letter in the original string to get a cool ouput.
This is my code so far but I got stuck:
function a = jamstr(strd,time)
for i = 0:1:length(strd)
z = i + 1;
expression = '^.*';
replace = '#';
newStr = regexprep(strd(z),expression,replace)
fprintf(newStr);
pause(time);
a=z;
if z == length(strd)
break
end
end
end

댓글 수: 3

BobH
BobH 2020년 3월 9일
I'm having difficulty understanding what you're asking.
- what would a sample 'strd' look like?
- what do you want the corresponding 'a' to look like?
Mansour Al Asais
Mansour Al Asais 2020년 3월 18일
jamstr('Matlabl rocks!',0.1)
What do you mean?
Ameer Hamza
Ameer Hamza 2020년 3월 18일
편집: Ameer Hamza 2020년 3월 18일
Mansour, what is the expected output for
jamstr('Matlab rocks!',0.1)

댓글을 달려면 로그인하십시오.

 채택된 답변

BobH
BobH 2020년 3월 18일
편집: BobH 2020년 3월 18일

1 개 추천

This is intentionally backwards from what you asked; adjusting it to start with all '#' is for you
function a = jamstr( strd, time )
fprintf( '%s', strd ); % print the entire string
% one backspace for each char
bkspaces = repmat('\b',size(strd));
fmt = [bkspaces '%s']; % format string for fprintf
for i = 1:length(strd)
newStr = strd;
newStr(i) = '#';
fprintf( fmt, newStr );
pause(time);
end
fprintf( fmt, strd ); % restore original
fprintf( '\n' ); % end on a fresh line
end

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

질문:

2020년 3월 9일

편집:

2020년 3월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by