Error when trying to plot with a datetime array
3 views (last 30 days)
Show older comments
I am trying to seperate the variable mFJ2 into two types based on the two parameter types in column 2 which are {'1'} and {'2'}. After I seperate them into two tables I am attempting to plot the first parameter which I made into an array called flowFJ2 against the array dateFJ2 but it is giving me this error:
Error using plot
Data must be numeric, datetime, duration or an array convertible to double.
So if someone could help me figure out how to fix this that would be great thanks!
Code:
%% Read the data
dataFJ2=readtable('Daily__Jun-20-2021_12_32_15PM.csv');
[a,b]=size(dataFJ2);
%getting the date
dateFJ2=table2array(dataFJ2(:,3));
%getting the parameter values
pFJ2=table2array(dataFJ2(:,2));
pFJ2=categorical(pFJ2);
categories(pFJ2)
%getting the measurement values
mFJ2=dataFJ2(:,4);
%putting into a table
TFJ2=table(pFJ2,dateFJ2,mFJ2);
p1FJ2=(TFJ2.pFJ2 == '1');
Tp1FJ2=TFJ2(p1FJ2,:);
p2FJ2=(TFJ2.pFJ2 == '2');
Tp2FJ2=TFJ2(p2FJ2,:);
dateFJ2=table2array(Tp1FJ2(:,2));
dateFJ2=datetime(dateFJ2, 'Format','yyyy/MM/dd');
flowFJ2=table2array(Tp1FJ2(:,3));
plot(dateFJ2,flowFJ2)
Accepted Answer
dpb
on 26 Jun 2021
tDaily=readtable('Daily__Jun-20-2021_12_32_15PM.csv','NumHeaderLines',1);
tDaily.ID=categorical(tDaily.ID);
tDaily.Date=datetime(tDaily.Date,'InputFormat','yyyy/MM/dd');
tDaily.SYM=categorical(tDaily.SYM);
>> head(tDaily)
ans =
8×5 table
ID PARAM Date Value SYM
_______ _____ ___________ _____ ___
01FJ002 1 01-Mar-1978 0.227 B
01FJ002 1 02-Mar-1978 0.195 B
01FJ002 1 03-Mar-1978 0.15 B
01FJ002 1 04-Mar-1978 0.136 B
01FJ002 1 05-Mar-1978 0.116 B
01FJ002 1 06-Mar-1978 0.108 B
01FJ002 1 07-Mar-1978 0.099 B
01FJ002 1 08-Mar-1978 0.093 B
[g,id]=findgroups(tDaily.PARAM);
for i=1:numel(unique(g))
figure
ix=(g==i);
plot(tDaily.Date(ix),tDaily.Value(ix))
title(compose('Daily Value vs Time PARAM = %d',i))
end
gives two figures.
We're having strong t-storm and my bandwith is so limited couldn't upload the figures themselves...
More Answers (0)
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!