Displaying chracters with the given input number
1 次查看(过去 30 天)
显示 更早的评论
Hello, I am looking for generating a code that displays number of chracters. For example, in the code, I will give the function a size represented as dots (.), if I give the size number as 5, I want it to display 5 dots such as ".....", and for other inpu numbers such as 10, I want it to display ".........." without quotation marks.
0 个评论
回答(2 个)
Deepak Gupta
2020-4-28
编辑:Deepak Gupta
2020-4-28
Hi Ahmet,
You can try below code for your requirement.
clear all; clc;
size = double(input('Enter Size: '));
x(1:size) = '.';
fprintf('\n%s\n', x);
To better understand strings without quotation refer this QA page.
Cheers.
Star Strider
2020-4-28
I am not certain exactly how you want to use this function.
Try this:
dotsfcn = @(nrdots) fprintf([repmat('.', 1, nrdots), '\n']);
One = dotsfcn(1);
Five = dotsfcn(5);
Ten = dotsfcn(10);
producing:
.
.....
..........
That prints to the Command Window.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!