Adding 0 value place holders to string array
34 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Lou
il 12 Dic 2024 alle 23:49
Modificato: Walter Roberson
il 13 Dic 2024 alle 3:18
Appreciate any help on this challenge. Ive spent a few hours already and havent figured it out. I have a 2500x1 string array. Lets say the first 5 rows look like this:
"0, 74, 46, 94"
"7, 64, 8"
"8, 50, 32, 70"
"6, 43"
"3, 55, 47"
How can I add zeros as place holders for the rows that have less than 4 values? I want the result to look like this:
"0, 74, 46, 94"
"7, 64, 8, 0"
"8, 50, 32, 70"
"6, 43, 0, 0"
"3, 55, 47, 0"
0 Commenti
Risposta accettata
Paul
il 13 Dic 2024 alle 1:03
s= [
"0, 74, 46, 94"
"7, 64, 8"
"8, 50, 32, 70"
"6, 43"
"3, 55, 47"]
c = count(s,",")
s = arrayfun(@(s,c) join([s,repmat(", 0",1,3-c)],""),s,c)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Introduction to Installation and Licensing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!