How do I create a table containing a character array if it has only one row?
67 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Are Mjaavatten
il 4 Mar 2022
Commentato: Csaba Zoltán Kertész
il 13 Mar 2022
This works fine:
Time = [1;2];Force = [12;17];ID = ['ab';'cd'];
T = table(Time,Force,ID)
But this fails:
Time = [1];Force = [12];ID = ['ab'];
T = table(Time,Force,ID)
There may be a good reason for this, but the behaviour does not seem logical to me.
Does anyone have good workaround?
1 Commento
Stephen23
il 4 Mar 2022
"There may be a good reason for this"
Yes: single character vectors are presumed to be part of name-value arguments.
Risposta accettata
Simon Chan
il 4 Mar 2022
Time = [1];Force = [12];ID = {'ab'};
T = table(Time,Force,ID)
Actually, the error message tells you the solution.
Time = [1];Force = [12];ID = ['ab'];
T = table(Time,Force,ID)
2 Commenti
Csaba Zoltán Kertész
il 13 Mar 2022
You could also try to use strings instead of character vectors if you do not want to hassle with cells:
Time = [1]; Force = [12]; ID = ["ab"];
T = table(Time, Force, ID)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su String Parsing 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!