![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1412409/image.png)
generate a string with the numbers 1:999
조회 수: 17 (최근 30일)
이전 댓글 표시
Hello! I need to generate a string with the numbers 1:999.
I wrote these lines of code:
row_number = 1:999;
column_number = row_number.';
conversion_column_number = num2str(column_number);
I want to eliminate the two spaces that are created before the numbers 1:9 and the space that is created between the numbers 10:99 in conversion_column_number. Is there a solution to this problem?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1412404/image.png)
댓글 수: 0
채택된 답변
Malay Agarwal
2023년 6월 16일
편집: Malay Agarwal
2023년 6월 16일
Hi, Alberto
Please try the following code:
row_number = 1:999;
column_number = row_number.';
conversion_column_number = string(column_number);
This has the following output:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1412409/image.png)
According to MATLAB documentation, the function num2str() converts the input array to a character array and MATALB makes sure that each element in a character array is of the same size, which is why you're getting the spaces.
댓글 수: 0
추가 답변 (1개)
Mayur
2023년 6월 16일
편집: Mayur
2023년 6월 16일
Hi!
I understand that you want to convert 'column_number' to a string without extra spaces.
You can use the 'string' function instead of 'num2str' here.
row_number = 1:999;
column_number = row_number.';
conversion_column_number = string(column_number);
Alternatively, you can try with this.
row_number = 1:999;
column_number = row_number.';
conversion_column_number = "" + column_number;
For more information you can refer the following documentation: https://www.mathworks.com/help/matlab/ref/string.html
댓글 수: 1
참고 항목
카테고리
Help Center 및 File Exchange에서 Naming Conventions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!