How can I plot this?

6 visualizaciones (últimos 30 días)
Pul
Pul el 2 de Sept. de 2021
Comentada: Star Strider el 2 de Sept. de 2021
Hello everyone,
I should plot the magenta data (Cum_smbp.SMB_mpmm) until 30/1/2019.
I tried in this way: plot(DTv,table2array(Cum_smbp(:,16),Cum_smbp.SMB_mpmm(1:7700),'m', 'DisplayName')), without success.
Can anyone help me please?
Thanks.
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})
smb=table2array(DATIECMWFgiornalieri(:,16))
for i =1:8402
if isnan(smb(i))
smb(i)=0;
end
end
Cum=cumsum(smb)
Cum_smbp=DATIECMWFgiornalieri;
Cum_smbp(:,16)=array2table(Cum)
plot(C,NEW, 'DisplayName')
hold on
plot(DTv,table2array(Cum_smbp(:,16)),'m', 'DisplayName');
plot(DTv,table2array(Cum_smbp(:,16),Cum_smbp.SMB_mpmm(1:7700),'m', 'DisplayName'));
legend('Location','best')

Respuesta aceptada

Star Strider
Star Strider el 2 de Sept. de 2021
Try this (slightly edited version) —
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.mat')
DTv = datetime(DATIECMWFgiornalieri{:,1:3});
smb=table2array(DATIECMWFgiornalieri(:,16));
smb = fillmissing(smb, 'constant',0);
% for i =1:8402
% if isnan(smb(i))
% smb(i)=0;
% end
% end
Cum=cumsum(smb);
Cum_smbp=DATIECMWFgiornalieri;
Cum_smbp(:,16)=array2table(Cum);
plot(C,NEW, 'DisplayName','First Plot')
hold on
plot(DTv,table2array(Cum_smbp(:,16)),'m', 'DisplayName','Second Plot');
plot(DTv,table2array(Cum_smbp(:,16),Cum_smbp.SMB_mpmm(1:7700)),'m', 'DisplayName','Third Plot');
legend('Location','best')
producing:
.
  6 comentarios
Pul
Pul el 2 de Sept. de 2021
Yes, now I got what I needed.
Thank you!
Star Strider
Star Strider el 2 de Sept. de 2021
As always, my pleasure!
.

Iniciar sesión para comentar.

Más respuestas (1)

Cris LaPierre
Cris LaPierre el 2 de Sept. de 2021
Editada: Cris LaPierre el 2 de Sept. de 2021
There are some inconsistencies in your code. The issue with the line you are questioning is that you have one X input and 2 Y inputs. You can plot multiple lines in a single plot command, but you must use the correct syntax.
Also note that DTv has 8402 rows and Cum_smbp.SMB_mpmm(1:7700) will have 7700, so you have more X data points than Y data points. This will give you an error.
You can use a logical array to identify data that meets a conditional requirement. See Ch 12 of MATLAB Onramp on how to do this. Use that array as an index to select the data to plot.
x=1:5;
y=x.^2;
ind = y<10
ind = 1×5 logical array
1 1 1 0 0
plot(x(ind),y(ind),'m-o')
Some other things
  • 'DisplayName' is a Name-Value pair input. You need to include both (e.g. plot(C,NEW, 'DisplayName','Line1')
  • It is best practice to always pair hold on with a corresponding hold off
  • There is no need to do table2array(Cum_smbp(...)). See the Access Data in Tables page for more.
  1 comentario
Pul
Pul el 2 de Sept. de 2021
Okay, thanks.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by