필터 지우기
필터 지우기

Displaying chracters with the given input number

조회 수: 1 (최근 30일)
Ahmet Uz
Ahmet Uz 2020년 4월 28일
댓글: Ahmet Uz 2020년 4월 29일
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.

답변 (2개)

Deepak Gupta
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.
  댓글 수: 1
Ahmet Uz
Ahmet Uz 2020년 4월 29일
Thank you for your answer, this was what I ask. I know matlab quite well, but these simple things can be tricky.

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


Star Strider
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.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by