How to convert table to an array when the first two variables are different?

5 vues (au cours des 30 derniers jours)
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
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.
andrea molina
andrea molina le 15 Avr 2017
here is the file! apparently I need to change the date and time columns to time vectors because when I try to plot graphs using them from the table they come out looking weird

Connectez-vous pour commenter.

Réponse acceptée

Peter Perkins
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
andrea molina
andrea molina le 25 Avr 2017
now from that code how would I go about creating variables for the specific months such as July or August? would I simply put August=(181:194,1)
Peter Perkins
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.

Connectez-vous pour commenter.

Plus de réponses (0)

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!

Translated by