How to convert table to an array when the first two variables are different?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
andrea molina
le 14 Avr 2017
Commenté : Peter Perkins
le 26 Avr 2017
Hello I have been working with this data set for a while and cannot get matlab to read it. The data consists of 8 variables and the first 2 are different. I will post my code and the error as well as what the data looks like.
date time pressure seatemp airtemp buoyhead windspd winddir
07/24/1994 12:00:00 1018.05 28.55 30.05 39.38 3.40 38.31
07/24/1994 13:00:00 1018.20 28.85 30.50 25.31 2.80 39.71
07/24/1994 14:00:00 1018.05 29.15 29.75 12.66 4.80 24.24
My code:
T=readtable('m17cm17.nodc','FileType','text','HeaderLines',57);
%%convert to an array
A = table2array(T)
Error: Cannot concatenate the table variables 'Var1' and 'Var2', because their types are datetime and cell.
4 commentaires
Stephen23
le 14 Avr 2017
@andrea molina: that just looks like a text file. Upload it after checking the file extension to .txt. Then we can help you.
Réponse acceptée
Peter Perkins
le 14 Avr 2017
Modifié(e) : Peter Perkins
le 14 Avr 2017
I don't understand your statement that you "cannot get matlab to read it". Based on the error message you get from table2array, you already have read the file. It's not clear exactly what variables readtable created in the table, but it's likely that you ended up with a mix of numeric and text. The error message is just saying that you can't combine the first two variables into one homogeneous array. But you already have them in a table, and combining variables with different types is the whole point of tables.
So it's not clear what you're really doing. You may be trying to combine date and time into one value, or something else. If that is what you're doing, read them both as test, concatenate them, and call datetime on the result.
7 commentaires
Peter Perkins
le 26 Avr 2017
I don't know what that means. If you want to create a logical variable in the table to indicate which rows are August
bouyData.isAugust = (bouyData.DateTime.Month) == 8)
But there are probably other better ways to do whatever you are doing.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Type Identification dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
