Cell contents reference from a non-cell array object table2array

조회 수: 1 (최근 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 CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by