How can I delete this data on the graph?

6 views (last 30 days)
Pul
Pul on 25 Nov 2021
Commented: Pul on 30 Nov 2021
Hello everyone,
for the wind percentage I don't want to plot the 1st value and the last value that you can see in the plot. I tried to replace them with NaN but it didnt' work.
How can I do?
Thank you!
load('giulia_TT.mat')
load('B');
giulia_daily=retime(giulia_TT,'daily',@(x)mean(x,1,'omitnan'));
%giulia_daily=retime(giulia_TT,'daily', @(x)mean(x,1,'omitnan')); %ottiengo i valori giornalieri
dates=datetime({'15 Dec 1998', '07 Dec 1999'; '07 Dec 1999', '30 Nov 2000';'30 Nov 2000','13 Nov 2001';'13 Nov 2001','30 Dec 2002';'30 Dec 2002','4 Jan 2004';'4 Jan 2004','22 Nov 2004';'22 Nov 2004','24 Nov 2005';'24 Nov 2005','15 Dec 2006';'15 Dec 2006','22 Jan 2008'; '22 Jan 2008','22 Jan 2009';'22 Jan 2009','22 Jan 2010';'22 Jan 2010','22 Jan 2011';'22 Jan 2011','22 Jan 2012';'22 Jan 2012','9 Jan 2013';'9 Jan 2013','5 Jan 2014';'5 Jan 2014','31 Jan 2015';'31 Jan 2015','31 Jan 2016';'31 Jan 2016','31 Jan 2017';'31 Jan 2017','25 Jan 2018';}, 'InputFormat','dd MMM yyyy'); % crei tabella con le coppie di date
date_len=[] % inizializzo il vettore che conta quanti giorni intercorrono tra le due date
date_len = []
for i=1:length(dates) % per ogni coppia di date
a=dates(i,2)-dates(i,1); %differenza(in ore) tra le due date
date_l(i)=days(a); % la transforma in giorni
date_len=date_l' % la aggiunge al vettore in modo da ottenere un vettore con tutte le differenze
end
date_len = 357
date_len = 2×1
357 359
date_len = 3×1
357 359 348
date_len = 4×1
357 359 348 412
date_len = 5×1
357 359 348 412 370
date_len = 6×1
357 359 348 412 370 323
date_len = 7×1
357 359 348 412 370 323 367
date_len = 8×1
357 359 348 412 370 323 367 386
date_len = 9×1
357 359 348 412 370 323 367 386 403
date_len = 10×1
357 359 348 412 370 323 367 386 403 366
date_len = 11×1
357 359 348 412 370 323 367 386 403 366
date_len = 12×1
357 359 348 412 370 323 367 386 403 366
date_len = 13×1
357 359 348 412 370 323 367 386 403 366
date_len = 14×1
357 359 348 412 370 323 367 386 403 366
date_len = 15×1
357 359 348 412 370 323 367 386 403 366
date_len = 16×1
357 359 348 412 370 323 367 386 403 366
date_len = 17×1
357 359 348 412 370 323 367 386 403 366
date_len = 18×1
357 359 348 412 370 323 367 386 403 366
date_len = 19×1
357 359 348 412 370 323 367 386 403 366
year_values=[] % inizializza
year_values = []
for i=1:length(dates)
date_a=dates(i,1); %prima data
date_b=dates(i,2); %seconda data
pos_a=find(giulia_daily.Time==date_a); %trovo la posizione della prima data in giulia_daily
pos_b=find(giulia_daily.Time==date_b); % uguale con la seconda
values_ab=B(pos_a:pos_b)*3.5; %prende tutti i valori tra le due date
mean_ab=mean(values_ab,1,'omitnan'); %fa la media
year_values(i)=mean_ab; % la aggiunge al vettore dei valori annuali
end
year_values=year_values'
year_values = 19×1
87.1801 137.0393 136.6014 142.1722 203.0924 235.8044 247.7685 333.2937 348.8429 355.1699
year_values_wind=[] % inizializza
year_values_wind = []
for i=1:length(dates)
date_a=dates(i,1); %prima data
date_b=dates(i,2); %seconda data
pos_a=find(giulia_daily.Time==date_a); %trovo la posizione della prima data in giulia_daily
pos_b=find(giulia_daily.Time==date_b); % uguale con la seconda
values_ab=giulia_daily.Var2(pos_a:pos_b); %prende tutti i valori tra le due date
mean_ab=mean(values_ab,1,'omitnan'); %fa la media
year_values_wind(i)=mean_ab; % la aggiunge al vettore dei valori annuali
end
year_values_wind=year_values_wind'
year_values_wind = 19×1
10.0999 11.2257 8.2535 11.6761 13.6418 10.5961 11.7224 11.0361 9.3854 11.6265
year_perc_wind=[] % inizializza
year_perc_wind = []
for i=1:length(dates)
date_a=dates(i,1); %prima data
date_b=dates(i,2); %seconda data
pos_a=find(giulia_daily.Time==date_a); %trovo la posizione della prima data in giulia_daily
pos_b=find(giulia_daily.Time==date_b); % uguale con la seconda
values_ab=giulia_daily.Var2(pos_a:pos_b); %prende tutti i valori tra le due date
values10=values_ab(values_ab>=10);
year_perc=length(values10)/length(values_ab)*100;
year_perc_wind(i)=year_perc% la aggiunge al vettore dei valori annuali
end
year_perc_wind = 25.9777
year_perc_wind = 1×2
25.9777 34.7222
year_perc_wind = 1×3
25.9777 34.7222 27.5072
year_perc_wind = 1×4
25.9777 34.7222 27.5072 51.0896
year_perc_wind = 1×5
25.9777 34.7222 27.5072 51.0896 56.8733
year_perc_wind = 1×6
25.9777 34.7222 27.5072 51.0896 56.8733 35.8025
year_perc_wind = 1×7
25.9777 34.7222 27.5072 51.0896 56.8733 35.8025 44.8370
year_perc_wind = 1×8
25.9777 34.7222 27.5072 51.0896 56.8733 35.8025 44.8370 40.5685
year_perc_wind = 1×9
25.9777 34.7222 27.5072 51.0896 56.8733 35.8025 44.8370 40.5685 31.6832
year_perc_wind = 1×10
25.9777 34.7222 27.5072 51.0896 56.8733 35.8025 44.8370 40.5685 31.6832 31.6076
year_perc_wind = 1×11
25.9777 34.7222 27.5072 51.0896 56.8733 35.8025 44.8370 40.5685 31.6832 31.6076 38.5246
year_perc_wind = 1×12
25.9777 34.7222 27.5072 51.0896 56.8733 35.8025 44.8370 40.5685 31.6832 31.6076 38.5246 39.0710
year_perc_wind = 1×13
25.9777 34.7222 27.5072 51.0896 56.8733 35.8025 44.8370 40.5685 31.6832 31.6076 38.5246 39.0710 62.8415
year_perc_wind = 1×14
25.9777 34.7222 27.5072 51.0896 56.8733 35.8025 44.8370 40.5685 31.6832 31.6076 38.5246 39.0710 62.8415 44.0678
year_perc_wind = 1×15
25.9777 34.7222 27.5072 51.0896 56.8733 35.8025 44.8370 40.5685 31.6832 31.6076 38.5246 39.0710 62.8415 44.0678 47.7901
year_perc_wind = 1×16
25.9777 34.7222 27.5072 51.0896 56.8733 35.8025 44.8370 40.5685 31.6832 31.6076 38.5246 39.0710 62.8415 44.0678 47.7901 42.8571
year_perc_wind = 1×17
25.9777 34.7222 27.5072 51.0896 56.8733 35.8025 44.8370 40.5685 31.6832 31.6076 38.5246 39.0710 62.8415 44.0678 47.7901 42.8571 34.9727
year_perc_wind = 1×18
25.9777 34.7222 27.5072 51.0896 56.8733 35.8025 44.8370 40.5685 31.6832 31.6076 38.5246 39.0710 62.8415 44.0678 47.7901 42.8571 34.9727 24.2507
year_perc_wind = 1×19
25.9777 34.7222 27.5072 51.0896 56.8733 35.8025 44.8370 40.5685 31.6832 31.6076 38.5246 39.0710 62.8415 44.0678 47.7901 42.8571 34.9727 24.2507 0
year_perc_wind=year_perc_wind'
year_perc_wind = 19×1
25.9777 34.7222 27.5072 51.0896 56.8733 35.8025 44.8370 40.5685 31.6832 31.6076
DateA=dates(:,1); % si crea una tabella in cui ho data1, data2, valore media
DateB=dates(:,2);
Year_Values=year_values;
giulia_year=table(DateA,DateB,Year_Values,year_values_wind,year_perc_wind)
giulia_year = 19×5 table
DateA DateB Year_Values year_values_wind year_perc_wind ___________ ___________ ___________ ________________ ______________ 15-Dec-1998 07-Dec-1999 87.18 10.1 25.978 07-Dec-1999 30-Nov-2000 137.04 11.226 34.722 30-Nov-2000 13-Nov-2001 136.6 8.2535 27.507 13-Nov-2001 30-Dec-2002 142.17 11.676 51.09 30-Dec-2002 04-Jan-2004 203.09 13.642 56.873 04-Jan-2004 22-Nov-2004 235.8 10.596 35.802 22-Nov-2004 24-Nov-2005 247.77 11.722 44.837 24-Nov-2005 15-Dec-2006 333.29 11.036 40.568 15-Dec-2006 22-Jan-2008 348.84 9.3854 31.683 22-Jan-2008 22-Jan-2009 355.17 11.626 31.608 22-Jan-2009 22-Jan-2010 379.09 12.534 38.525 22-Jan-2010 22-Jan-2011 401.24 10.553 39.071 22-Jan-2011 22-Jan-2012 426.96 12.286 62.842 22-Jan-2012 09-Jan-2013 511.63 10.968 44.068 09-Jan-2013 05-Jan-2014 595.61 11.364 47.79 05-Jan-2014 31-Jan-2015 607.34 10.866 42.857
%%%% Calcoliamo la differenza
diff_values=[]
diff_values = []
for i=2:length(dates)
val_a=giulia_year.Year_Values(i-1);
val_b=giulia_year.Year_Values(i);
diff_ab=val_b-val_a;
diff_values(i)=diff_ab;
end
diff_values(1)=NaN;
Diff_Values=diff_values';
giulia_year=table(DateA,DateB,Year_Values,Diff_Values,year_values_wind,year_perc_wind);
plot(giulia_year.DateA, giulia_year.year_perc_wind, '-*', 'Color','g', 'MarkerFaceColor','g')
grid

Accepted Answer

Peter Perkins
Peter Perkins on 26 Nov 2021
This is a lot of code that I just can't follow. I will suggest that a loop l;ike this
for i=1:length(dates) % per ogni coppia di date
a=dates(i,2)-dates(i,1); %differenza(in ore) tra le due date
date_l(i)=days(a); % la transforma in giorni
date_len=date_l' % la aggiunge al vettore in modo da ottenere un vettore con tutte le differenze
end
is easily replaced by one line:
datelen = caldays(dates(:,2) - dates(:,1))
or even
datelen = caldays(diff(dates,[],2))
Doing this will make you code much easier to read. Notice that I've used caldays: at some point you may end up using time zones, at which point days (i.e. 24hrs) will not give the right answer.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!