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

5 views (last 30 days)
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 Comments
Stephen23
Stephen23 on 14 Apr 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 on 15 Apr 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

Sign in to comment.

Accepted Answer

Peter Perkins
Peter Perkins on 14 Apr 2017
Edited: Peter Perkins on 14 Apr 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 Comments
andrea molina
andrea molina on 25 Apr 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 on 26 Apr 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.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Type Identification in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!