I get an error when running anomaly time series code in the app designer.

1 view (last 30 days)
I created an anomaly time series function. I want to plot this in the app designer but I get the following error: Error using plot Data must be numeric, datetime, duration or an array convertible to double. I get this error in the plot section. How can I fix this?
function LoadButton_2Pushed(app, event)
lat = app.EpochEditField_4.Value;
lon = app.EpochEditField_5.Value;
year = app.EpochEditField_3.Value;
month = app.EditField_3.Value;
day = app.EditField_4.Value;
k = datetime(year,month,day);
doy = datenum([year,month,day, 0, 0, 0]) - datenum([year, 1, zeros(1, 4)]);
yearstr=num2str(year);
nn=['CODG' sprintf('%03s',num2str((doy))) '0.' yearstr(3:4) 'I' '.mat'];
fid = nn;
grid_point=whichGrid(lat,lon,fid);
grid_lat=floor(lat/2.5)*2.5;
grid_lon=floor(lon/5)*5;
d_lat=(lat-grid_lat)/5;
d_lon=(lon-grid_lon)/5;
whichFile=strsplit(fid,'.');
whichType=(whichFile{1,1}(1:end-4));
load('allMatrix.mat'); %
if whichType == "CODG"
files1=all(:,1);
elseif whichType == "COPG"
files1=all(:,2);
elseif whichType == "Anomaly"
files1=all(:,3);
end
totalFiles = numel(files1);
for i=1:totalFiles
if isequaln(fid,(files1(i).name))
last_day=i;
first_day=i-29;
end
end
allTEC=[];
timeser=[];
for k=1:16
del1=[];
del2=[];
del3=[];
del4=[];
for j= first_day-1+k : first_day+13+k
dd=load(files1(j).name);
del1=[del1 , dd.Ionex.TECU(grid_point(1,1),grid_point(1,2),:)];
del2=[del2 , dd.Ionex.TECU(grid_point(1,1)-1,grid_point(1,2),:)];
del3=[del3 , dd.Ionex.TECU(grid_point(1,1),grid_point(1,2)+1,:)];
del4=[del4 , dd.Ionex.TECU(grid_point(1,1)-1,grid_point(1,2)+1,:)];
end
allTEC1(k,:,:)=del1;
allTEC2(k,:,:)=del2;
allTEC3(k,:,:)=del3;
allTEC4(k,:,:)=del4;
timeser=[timeser ; dd.Ionex.EpochOfCurrentMap];
end
timeser=timeser(1:195,:);%
timeser=cell2mat(timeser);
for j=1:13
for k=1:16
for i=1:15
allTEC(k,i,j)=[1-d_lon, d_lon ]*[allTEC1(k,i,j), allTEC2(k,i,j);
allTEC3(k,i,j) ,allTEC4(k,i,j)]/10*[1-d_lat; d_lat];
end
end
end
formatIn = 'yyyy mm dd HH MM SS';
[Y,M,D,H,Mn,S] = datevec(timeser,formatIn);
date_e = datenum(Y,M,D,H,Mn,S);
date_e=datestr(date_e);
days_mean=mean(allTEC(1:15,:,:));%
if whichType=="Anomaly"
d16band=2.0*std(allTEC(1:15,:,:)); %
else
d16band=1.34*std(allTEC(1:15,:,:)); %
end
real=allTEC(2:16,15,:);
real=permute(real, [2 1 3]);
u_l_band=[days_mean + d16band; days_mean - d16band; real];
new=[];
for m=1:13
new=[new u_l_band(:,:,m)];
end
new=new/10;
[~,col]=size(new);
anomaly_time=[];
anomaly_values=[];
for i=1:col
if new(3,i)> new(1,i) || new(3,i)< new(2,i)
anomaly_time=[anomaly_time ; date_e(i,:)];
anomaly_values=[anomaly_values new(:,i)];
end
end
ts1=timeseries(new,date_e,'name','Tec Values');
ax=app.UIAxes6;
plot(ax,ts1)
grid on
end

Accepted Answer

Geoff Hayes
Geoff Hayes on 10 Jun 2020
Özge - the output of timeseries is an object and so you need to plot the appropriate data from this object and not the object itself. The error message is telling you that the ts1 is an invalid parameter for plot because it is NOT numeric, datetime, duration or an array convertible to double. Consider the following example (from my version of MATLAB so may differ from yours),
>> ts1 = timeseries((1:5)','Name','MyTimeSeries')
timeseries
Common Properties:
Name: 'MyTimeSeries'
Time: [5x1 double]
TimeInfo: [1x1 tsdata.timemetadata]
Data: [5x1 double]
DataInfo: [1x1 tsdata.datametadata]
More properties, Methods
If I want to plot the data vs time, i would then do
>> plot(ts1.Time, ts1.Data)
  1 Comment
Özge
Özge on 10 Jun 2020
Hello, thank you very much for the answer. but I would like something more. I asked the last 1 question about the application designer and I did not get the answer to that question from anyone. It is very important for me to find the answer. Link to my question: https://www.mathworks.com/matlabcentral/answers/545450-how-can-i-show-the-result-of-my-function-in-uiaxes-problem-with-copyobj
I will be very happy if you can help. thank you

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer 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!