Displaying chracters with the given input number

1 visualización (últimos 30 días)
Ahmet Uz
Ahmet Uz el 28 de Abr. de 2020
Comentada: Ahmet Uz el 29 de Abr. de 2020
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.

Respuestas (2)

Deepak Gupta
Deepak Gupta el 28 de Abr. de 2020
Editada: Deepak Gupta el 28 de Abr. de 2020
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.
  1 comentario
Ahmet Uz
Ahmet Uz el 29 de Abr. de 2020
Thank you for your answer, this was what I ask. I know matlab quite well, but these simple things can be tricky.

Iniciar sesión para comentar.


Star Strider
Star Strider el 28 de Abr. de 2020
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.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by