storing matrix elements in a single variable as string

3 ビュー (過去 30 日間)
Karanvir singh Sohal
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 Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by