how to convert vector in string as example

 採用された回答

Voss
Voss 2023 年 9 月 2 日

2 投票

c=1; 
a=[4 7]
sprintf("cnt %d - [",c) + num2str(a) + "]"

4 件のコメント

shamal
shamal 2023 年 9 月 2 日
i made a change to my code.. is it possible to use the cell array to create this string?
"cnt 1 - [0 0]" "'cnt 2 - [4 6]" "cnt 3 - [6 8]" ....
I'm looking for the same result (using 1x6 cell as example)
{'cnt 1 - [0 0]'} {'cnt 2 - [4 6]'} {'cnt 3 - [6 8]'} {'cnt 4 - [1 2]'} {'cnt 5 - [8 9]'} {'cnt 6 - [3 2]'}
Voss
Voss 2023 年 9 月 2 日
load matlab_conv.mat
C = [conv{:}];
compose('cnt - %d [%d %d]',[C{:}])
ans = 1×6 cell array
{'cnt - 1 [0 0]'} {'cnt - 2 [0 0]'} {'cnt - 3 [0 0]'} {'cnt - 4 [0 0]'} {'cnt - 5 [0 0]'} {'cnt - 6 [0 0]'}
shamal
shamal 2023 年 9 月 2 日
thank you
Voss
Voss 2023 年 9 月 2 日
You're welcome!

サインインしてコメントする。

その他の回答 (1 件)

Alexander
Alexander 2023 年 9 月 2 日

0 投票

My solution:
c=1;
a=[4 7]
resultTxT =['"cnt ' num2str(c) ' - [' num2str(a) ']"']

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

質問済み:

2023 年 9 月 2 日

コメント済み:

2023 年 9 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by