how to convert vector in string as example

 Akzeptierte Antwort

Voss
Voss am 2 Sep. 2023

2 Stimmen

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

4 Kommentare

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Alexander
Alexander am 2 Sep. 2023

0 Stimmen

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

Kategorien

Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 2 Sep. 2023

Kommentiert:

am 2 Sep. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by