Cell contents reference from a non-cell array object table2array

2 ビュー (過去 30 日間)
Hannah Joyce
Hannah Joyce 2018 年 7 月 6 日
コメント済み: Hannah Joyce 2018 年 7 月 6 日
% 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 件のコメント
Paolo
Paolo 2018 年 7 月 6 日
編集済み: Paolo 2018 年 7 月 6 日
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 2018 年 7 月 6 日
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?

サインインしてコメントする。

回答 (2 件)

Jan
Jan 2018 年 7 月 6 日
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.
  1 件のコメント
Hannah Joyce
Hannah Joyce 2018 年 7 月 6 日
Undefined variable "Data" or class "Data.Dst_val".
Error in dstvsae (line 10)
class(Data.Dst_val)

サインインしてコメントする。


Peter Perkins
Peter Perkins 2018 年 7 月 6 日
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.
  1 件のコメント
Hannah Joyce
Hannah Joyce 2018 年 7 月 6 日
thank you :)
its the auroral electrojet data in the ionosphere from september 1993

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by