Cell contents reference from a non-cell array object table2array

2 views (last 30 days)
% import data and convert into an array
a = open('dst1993.mat');
x = table2array(a.Dst_val);
b = open('ae1993.mat');
x2 = table2array(b.AE_val);
gets me error:
Cell contents reference from a non-cell array object.
Error in table2array (line 27)
a = t{:,:};
Error in dstvsae (line 11)
x = table2array(a.Dst_val);
I'm really bad at coding but I need to get this done :/
  6 Comments
Paolo
Paolo on 6 Jul 2018
Edited: Paolo on 6 Jul 2018
Those are serial date numbers. Read more about it here.
What is the desired output for your dates? Try:
a = load('dst1993.mat');
dates = datetime(a.Dst_val(1:720),'ConvertFrom','datenum')';
values = a.Dst_val(721:end)';
T = table(dates,values)
T is a now a Table containing variables dates and values. Then simply plot your data:
plot(T.dates,T.values);
Hannah Joyce
Hannah Joyce on 6 Jul 2018
so if I wanted to plot this data set on the same time axis (time is column one, columns 2, 3 and 4 are different data sets) I'd just copy that and edit it to be ae1993.mat and AE_val instead of Dst?
or would it be a bit more complicated as there are 3 columns of different data?

Sign in to comment.

Answers (2)

Jan
Jan on 6 Jul 2018
Start with:
Data = load('dst1993.mat')
What do you get for:
class(Data.Dst_val)
? If you know this, the conversion to an array should be easy.

Peter Perkins
Peter Perkins on 6 Jul 2018
In a recent-ish version of MATLAB, try this:
>> load('ae1993.mat')
>> t = array2table(AE_val,'VariableNames',{'Time' 'X' 'Y' 'Z' 'W'});
>> t.Time = datetime(t.Time,'ConvertFrom','datenum');
>> tt = table2timetable(t);
>> head(tt)
ans =
8×4 timetable
Time X Y Z W
____________________ __ __ ___ __
01-Sep-1993 00:00:00 35 28 -6 10
01-Sep-1993 01:00:00 36 26 -9 8
01-Sep-1993 02:00:00 80 49 -30 8
01-Sep-1993 03:00:00 50 40 -9 15
01-Sep-1993 04:00:00 47 37 -9 13
01-Sep-1993 05:00:00 36 23 -13 4
01-Sep-1993 06:00:00 44 27 -16 4
01-Sep-1993 07:00:00 48 32 -16 7
>> plot(tt.Time,tt.Variables)
That's kind of pretty.

Categories

Find more on Dates and Time in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!