How to add commas after cell array strings
44 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Martynas Subonis
am 25 Nov. 2015
Kommentiert: Star Strider
am 25 Nov. 2015
Hello,
I'm stuck with one problem for a few hours right now. I want to add commas after my cell array string. Right now it looks like:
a = {'a1','a2','a3','a4','a5','a6'}; a(:)'
ans =
'a1' 'a2' 'a3' 'a4' 'a5' 'a6'
But I need it to be like this:
'a1' , 'a2' , 'a3' , 'a4' , 'a5' , 'a6'
(No comma after last one). I tried a lot of ways, but it seems that I can't create my strings in cell array in form of 'a1', initially. strjoin and strcat doesn't seem to solve this problem as well. I'm kinda lost.
0 Kommentare
Akzeptierte Antwort
Star Strider
am 25 Nov. 2015
A cell array is by definition a Comma-Separated List. If you want it to appear in your Command Window as one with distinct commas, this works:
a = {'a1','a2','a3','a4','a5','a6'};
fprintf(1, 'a = ')
for k1 = 1:length(a)-1
fprintf(1, '%s , ', char(a(k1)'))
end
fprintf(1, '%s\n', char(a(end)))
a = a1 , a2 , a3 , a4 , a5 , a6
5 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!