Export doubletimeseries dataset from MATLAB to Excel

5 vues (au cours des 30 derniers jours)
DB
DB le 18 Jan 2021
Hi, I have data from Simulink out.conout colum time and 7 others:
I want to export this to excel. I've tried writetable, xlswrite and other functions but do not yet get the desired results. Can anyone help?
  21 commentaires
DB
DB le 26 Jan 2021
Glad to! But I don't see the button?
Mathieu NOE
Mathieu NOE le 27 Jan 2021
I have to put my suggestion into the answer section, so you can accept it

Connectez-vous pour commenter.

Réponse acceptée

Mathieu NOE
Mathieu NOE le 27 Jan 2021
so official answer below :
------------------------------------
hey , success !!
here is it !
excel output in attachement, could easily plot the staircase data
n=100;
x1=12; %household with high energy usage (in kWh per day)
x2=7.57; %household with just above average daily energy usage (Netherlands)
x0=[x1;x2];
% a11=0.8;
% a12=0.2;
% a21=0.3;
% a22=0.7;
a11=0.70;
a12=0.10;
a21=0.20;
a22=0.65;
A=[a11 a12; a21 a22];
% b1=0.1;
% b2=0.15;
% B=[b1 0;0 b2];
b11=0.19;
b12=0.01;
b21=0.00;
b22=0.15;
B=[b11 b12;b21 b22];
c1=0.8;
c2=0.6;
C=[c1 0;0 c2];
D=eye(2)-C;
x=nan(2,n);
x(:,1)=x0;
d0=x0;
Ts=5;
% Ab=[A(1,1)*(1-sum(B(1,:))) A(1,2)*(1-sum(B(1,:)));
% A(2,1)*(1-sum(B(2,:))) A(2,2)*(1-sum(B(2,:)))];
% L=[1 -1;-1 1];
sim('impexsim');
time1 = conout.Time;
x1 = conout.Data(:,1);
x2 = conout.Data(:,2);
time2 = disout.Time;
d1 = interp1(time2,disout.Data(:,1),time1,'previous');
d2 = interp1(time2,disout.Data(:,2),time1,'previous');
figure(1)
plot(conout)
title('Impulsive dynamics of x1 and x2')
ylabel('Energy usage in (kWh)')
xlabel('Time t in (days)')
hold on
plot(disout)
legend('x1(t)','x2(tk)','d1(t)','d2(tk)','location','southeast')
ylim([5 13])
% figure(2)
% plot(time1,[x1 x2 d1 d2]); % must be the same as fig 1
figure(3)
[time11,x11,x22,d11,d22] = mystaircase(time1,x1,x2,time2,d1,d2);
plot(time11,[x11 x22 d11 d22]); % must be the same as fig 1
% as all data are now resampled with time11 common time base ,
% we will save to excel in one step
T1 = table(time11,x11,x22,d11,d22)
writetable(T1,'myData2.xlsx','Sheet',1,'Range','A1:E100')
function [time11,x11,x22,d11,d22] = mystaircase(time1,x1,x2,time2,d1,d2)
% data to replicate corresponding to t = 5 / 10 /15 (remove first and last
% index of time2 before)
[LIA,LOCB] = ismembertol(time1,time2(2:end-1),1e-6);
time11 = [];
d11 = [];
d22 = [];
x11 = [];
x22 = [];
for ci = 1:numel(LOCB)
if LOCB(ci) < 1
time11 = [time11; time1(ci)];
d11 = [d11; d1(ci)];
d22 = [d22; d2(ci)];
x11 = [x11; x1(ci)];
x22 = [x22; x2(ci)];
else % here we duplicate the values
time11 = [time11; time1(ci); time1(ci)];
d11 = [d11; d1(ci-1); d1(ci)];
d22 = [d22; d2(ci-1); d2(ci)];
x11 = [x11; x1(ci-1); x1(ci)];
x22 = [x22; x2(ci-1); x2(ci)];
end
end
end

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by