PLEASE HOW TO PLOT LINE GRAPH AND TABLE OF THE ATTACHED FILE.THANKS
MATLAB: HOW TO PLOT TABLE AND GRAPH
line graphtable
Related Solutions
Hi Jinang,
In your code, the first column of "A" is not a datetime. It is just numeric value calculated by using division operator (/). You should construct two variables: one for datetime, and the other for numeric data. Here is one solution to your problem.
date = [datetime(2019,10,20);datetime(2019,11,12)];point = [5;6];table = table(date, point);plot(table.date,table.point)
If you have R2014b or later, use tables and datetimes. For the specific question you've asked, simplest to use ismember and indexing:
>> Date = datetime({'01/01/2015';'01/14/2015';'05/30/2015'});>> Value = [10; 5; 10];>> TSomeDays = table(Date,Value)TSomeDays = Date Value ___________ _____ 01-Jan-2015 10 14-Jan-2015 5 30-May-2015 10 >> Date = datetime(2015,1,(1:180)');>> Value = zeros(size(Date));>> TAllDays = table(Date,Value);>> [~,i] = ismember(TSomeDays.Date,TAllDays.Date)i = 1 14 150>> TAllDays.Value(i) = TSomeDays.ValueTAllDays = Date Value ___________ _____ 01-Jan-2015 10 02-Jan-2015 0 [snip] 13-Jan-2015 0 14-Jan-2015 5 15-Jan-2015 0 [snip] 29-May-2015 0 30-May-2015 10 31-May-2015 0 [snip]>> Date = datetime(2015,1,(1:365)');>> TAllDays = table(Date);
Another possibility is to use an outer join, which may be too heavy of a hammer for this specific question, but which provides capabilities that you may yet need. outerjoin fills missing values with NaN, but you can put zeros in their place:
>> TAllDays = outerjoin(TAllDays,TSomeDays,'Key','Date','MergeKeys',true)TAllDays = 365×2 table Date Value ___________ _____ 01-Jan-2015 10 02-Jan-2015 NaN 03-Jan-2015 NaN [snip] 13-Jan-2015 NaN 14-Jan-2015 5 15-Jan-2015 NaN [snip] 29-May-2015 NaN 30-May-2015 10 31-May-2015 NaN [snip]>> TAllDays.Value(isnan(TAllDays.Value)) = 0TAllDays = Date Value ___________ _____ 01-Jan-2015 10 02-Jan-2015 0 [snip] 13-Jan-2015 0 14-Jan-2015 5 15-Jan-2015 0 [snip] 29-May-2015 0 30-May-2015 10 31-May-2015 0 [snip]
If you have R2016b, this is trivial using a timetable:
>> Date = datetime(2015,1,(1:365)');>> TTAllDays = retime(TTSomeDays,Date,'FillWithConstant','Constant',0)TTAllDays = Date Value ___________ _____ 01-Jan-2015 10 02-Jan-2015 0 [snip] 13-Jan-2015 0 14-Jan-2015 5 15-Jan-2015 0 [snip] 29-May-2015 0 30-May-2015 10 31-May-2015 0 [snip]
Best Answer