how to convert vector in string as example

 采纳的回答

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

4 个评论

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]'}
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]'}

请先登录,再进行评论。

更多回答(1 个)

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

类别

帮助中心File 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