storing matrix elements in a single variable as string

3 次查看(过去 30 天)
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 个)

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