how to convert vector in string as example

 Réponse acceptée

Voss
Voss le 2 Sep 2023

2 votes

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

4 commentaires

shamal
shamal le 2 Sep 2023
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]'}
shamal
shamal le 2 Sep 2023
thank you
Voss
Voss le 2 Sep 2023
You're welcome!

Connectez-vous pour commenter.

Plus de réponses (1)

Alexander
Alexander le 2 Sep 2023

0 votes

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

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by