Hello!
I want to join the multiple int from the matrix and save them as a string. Let us say I have a matrix A.
A = [3 25 100 5 20 100];
I want to store these values in B as following
B=("3#25@100","5#20@100")
Thanks in advance.

 채택된 답변

Fangjun Jiang
Fangjun Jiang 2021년 3월 29일

0 개 추천

Use for-loop if want to split
A = [3 25 100 5 20 100];
>> B=sprintf("%d#%d@%d\n",A(:))
B =
"3#25@100
5#20@100
"

댓글 수: 1

Thanks buddy
This is what exactly Ii was looking for
B=sprintf('"%d#%d@%d,%d#%d@%d"',A(:))

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

추가 답변 (1개)

A = [3,25,100,5,20,100];
S = compose("%d#%d@%d",A)
S = 1×2 string array
"3#25@100" "5#20@100"

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by