storing matrix elements in a single variable as string

조회 수: 1 (최근 30일)
Karanvir singh Sohal
Karanvir singh Sohal 2021년 3월 29일
댓글: Karanvir singh Sohal 2021년 3월 29일
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일
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
Karanvir singh Sohal
Karanvir singh Sohal 2021년 3월 29일
Thanks buddy
This is what exactly Ii was looking for
B=sprintf('"%d#%d@%d,%d#%d@%d"',A(:))

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

추가 답변 (1개)

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

카테고리

Help CenterFile 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