storing matrix elements in a single variable as string

2 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 29 Mär. 2021
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 Kommentar
Karanvir singh Sohal
Karanvir singh Sohal am 29 Mär. 2021
Thanks buddy
This is what exactly Ii was looking for
B=sprintf('"%d#%d@%d,%d#%d@%d"',A(:))

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Stephen23
Stephen23 am 29 Mär. 2021
A = [3,25,100,5,20,100];
S = compose("%d#%d@%d",A)
S = 1×2 string array
"3#25@100" "5#20@100"

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by