V = [1 2 3 4 5];
strcat ('R = ', strjoin(string( V),', '))
I got the following answer while running the above code
"R =1, 2, 3, 4, 5"
But i need (a white space after '=' sign)
"R = 1, 2, 3, 4, 5"

댓글 수: 1

The solution is already given in the STRCAT documentation:
V = 1:5;
strcat({'R = '},strjoin(string( V),', '))
ans = "R = 1, 2, 3, 4, 5"

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

 채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 12월 26일

0 개 추천

You can use strjoin again -
V = [1 2 3 4 5];
out1 = strjoin(["R =" strjoin(string(V),', ')])
out1 = "R = 1, 2, 3, 4, 5"
You can also add strings like this -
out2 = "R = " + strjoin(string(V),', ')
out2 = "R = 1, 2, 3, 4, 5"

추가 답변 (1개)

Image Analyst
Image Analyst 2023년 12월 26일

0 개 추천

V = [1 2 3 4 5];
str = sprintf('R = %s', strjoin(string( V),', '))
str = 'R = 1, 2, 3, 4, 5'

카테고리

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

질문:

2023년 12월 26일

댓글:

2023년 12월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by