Why this variable doesn't appear?

Hello everyone,
I'm trying to do a cumulate of 'DATI_ECM_GIORNALIERI' but the variable doesn't appear.
Then, I only have to plot it (eg Cum_Giul.SMB_mpmm) instead of DATIECMWFgiornalieri.SMB_mpmm, as you can see at the end of the plot.
Thank you very much.
clear all
close all
load('GIULIA_MMEQ1.mat');
A=GIULIAMMEQ1.Var4;
B=str2double(A);
NEW= B * 10 * 0.35;
C=GIULIAMMEQ1.Dec1997;%array2table
C=replace(C,"';","");
C=datetime(C,'InputFormat','dd MMM yyyy'); %convert to datetime format
plot(C,NEW)
load('DATI_ECM_GIORNALIERI')
DTv = datetime(DATIECMWFgiornalieri{:,1:3})
DTv = 8402×1 datetime array
01-Jan-1998 02-Jan-1998 03-Jan-1998 04-Jan-1998 05-Jan-1998 06-Jan-1998 07-Jan-1998 08-Jan-1998 09-Jan-1998 10-Jan-1998 11-Jan-1998 12-Jan-1998 13-Jan-1998 14-Jan-1998 15-Jan-1998 16-Jan-1998 17-Jan-1998 18-Jan-1998 19-Jan-1998 20-Jan-1998 21-Jan-1998 22-Jan-1998 23-Jan-1998 24-Jan-1998 25-Jan-1998 26-Jan-1998 27-Jan-1998 28-Jan-1998 29-Jan-1998 30-Jan-1998
Cum_Giul=retime(DATIECMWFgiornalieri,'daily', @(x)sum(x,'omitnan'))
Check for incorrect argument data type or missing argument in call to function 'retime'.
figure
yyaxis left
plot(C,NEW, 'DisplayName','AWS')
yyaxis right
plot(DTv, DATIECMWFgiornalieri.SMB_mpmm,'m', 'DisplayName','ECMWF');
% plot(DTv, DATIECMWFgiornalieri.SMB_mpmm,'m-*', 'DisplayName','ECMWF');
Ax = gca;
Ax.YAxis(2).Color = 'm';
legend('Location','best')

 Réponse acceptée

Walter Roberson
Walter Roberson le 26 Août 2021
DATIECMWFgiornalieri is a table() object. You cannot retime() a table() object. You need to take that Dtv you created and
Cum_Giu = retime(table2timetable(DATIECMWFgiornalieri, 'RowTimes', DTv), 'daily', @(x)sum(x,'omitnan'))

8 commentaires

Thank you.
But now I can't plot them because vectors have different length.
How can I solve it?
plot(DTv, Cum_Giu.SMB_mpmm,'m', 'DisplayName','ECMWF');
One thing:
Cum_Giu = retime(table2timetable(DATIECMWFgiornalieri, 'RowTimes', DTv), 'daily', @(x)sum(x,1,'omitnan'))
Otherwise you get problems in cases where there was only one entry for a given day.
CTv = Cum_Gui.Properties.RowTimes;
plot(CTv, Cum_Giu.SMB_mpmm, 'm', 'DisplayName','ECMWF');
@Walter Roberson now it works, thank you.
But I got 2 different plots instead one, despite using "hold on". How can I solve it?
Thank you.
Cum_Giu = retime(table2timetable(DATIECMWFgiornalieri, 'RowTimes', DTv), 'daily', @(x)sum(x,1,'omitnan'))
CTv = Cum_Giu.Properties.RowTimes;
figure
plot(CTv, Cum_Giu.SMB_mpmm, 'm', 'DisplayName','ECMWF');
hold on
figure
yyaxis left
hold on
plot(C,NEW, 'DisplayName','AWS')
yyaxis right
Ax = gca;
Ax.YAxis(2).Color = 'm';
legend('Location','best')
Walter Roberson
Walter Roberson le 26 Août 2021
hold on only affects things drawn in the same axes. Your second call to figure creates a new figure and the yyaxis left then looks at the current figure (newly created), sees it has no axes, and so creates an axes in the new figure, which you then draw AWS into. If you wanted it to go into the same plot ECMWF went into, you should not have called figure() with no parameters.
Pul
Pul le 26 Août 2021
yes, but if I delete "figure" I get something different, as you can see in the image.
Cum_Giu = retime(table2timetable(DATIECMWFgiornalieri, 'RowTimes', DTv), 'daily', @(x)sum(x,1,'omitnan'))
CTv = Cum_Giu.Properties.RowTimes;
yyaxis left
plot(CTv, Cum_Giu.SMB_mpmm, 'm', 'DisplayName','ECMWF');
yyaxis right
plot(C,NEW, 'DisplayName','AWS')
Ax = gca;
Ax.YAxis(2).Color = 'm';
legend('Location','best')
Pul
Pul le 26 Août 2021
Thank you.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by