Read and write multiple times in excel document - for loop or?

2 visualizaciones (últimos 30 días)
Jakob
Jakob el 23 de Feb. de 2016
Comentada: Stephen23 el 24 de Feb. de 2016
Hi,
I am using polyfit to fit the dataset I have.
function Polyfit_data(x_colomn,y_colomn,cell_with_power_value)
x1=xlsread('data.xlsx','data',x_colomn); %'x' data from simulation or measurement
y1=xlsread('data.xlsx','data',y_colomn); %'y' data from simulation or measurement
power=xlsread('data.xlsx','data',cell_with_power_value); %power dissipated in device
p=polyfit(x1,y1,20);
xlswrite('polyfitdata.xlsx',p,'b1:bb1');
xlswrite('polyfitdata.xlsx',power,'a1:a1');
my data I have sorted so that the first dataset have x's in a:a, y's in b:b and power=c1, next dataset then have x's in d:d, y's in e:e and power=f1 ... This continiues for multiple dataset.
Each data set is read and then a polyfit function is found and written in another excel document. Here I write the polynomia from b1:bb1 and power value in a1.
First I am not sure if I should write it back to an excel file - since when I am using the data later I have to read them and it takes quiet some time. Second I would really like to make the function as a loop where I only define how many dataset to read. Then I just need to be careful that the data is organized in the right way.
The script I am using later is simply reading the polyfit functions, linearise for power input and then adding the plots together to give a sum.
t_end=xlsread('polyfitdata.xlsx','parameters','b5:b5');
stepsize=xlsread('polyfitdata.xlsx','parameters','b6:b6');
Ta=xlsread('polyfitdata.xlsx','parameters','b7:b7');
x0=0:stepsize:t_end;
%die1 settings
t_0_die1=xlsread('polyfitdata.xlsx','parameters','b2:b2');
pow11=xlsread('polyfitdata.xlsx','polyfitdata','b2:b2');
pow14=xlsread('polyfitdata.xlsx','polyfitdata','b3:b3');
power1=xlsread('polyfitdata.xlsx','parameters','b3:b3');
p11=xlsread('polyfitdata.xlsx','polyfitdata','c2:w2');
p14=xlsread('polyfitdata.xlsx','polyfitdata','c3:w3');
%die2 settings
t_0_die2=xlsread('polyfitdata.xlsx','parameters','c2:c2');
pow21=xlsread('polyfitdata.xlsx','polyfitdata','b4:b4');
pow24=xlsread('polyfitdata.xlsx','polyfitdata','b5:b5');
power2=xlsread('polyfitdata.xlsx','parameters','c3:c3');
p21=xlsread('polyfitdata.xlsx','polyfitdata','c4:w4');
p22=xlsread('polyfitdata.xlsx','polyfitdata','c5:w5');
%die3 settings
t_0_die3=xlsread('polyfitdata.xlsx','parameters','d2:d2');
pow31=xlsread('polyfitdata.xlsx','polyfitdata','b6:b6');
pow34=xlsread('polyfitdata.xlsx','polyfitdata','b7:b7');
power3=xlsread('polyfitdata.xlsx','parameters','d3:d3');
p31=xlsread('polyfitdata.xlsx','polyfitdata','c6:w6');
p32=xlsread('polyfitdata.xlsx','polyfitdata','c7:w7');
%die1
x1=0:stepsize:t_end-t_0_die1;
y1=[zeros(1,size(x0,2)-size(x1,2)),(polyval(p14,x1)-polyval(p11,x1))/(pow14-pow11)*power1];
%die2
x2=0:stepsize:t_end-t_0_die2;
y2=[zeros(1,size(x0,2)-size(x2,2)),(polyval(p22,x2)-polyval(p21,x2))/(pow24-pow21)*power2];
%die3
x3=0:stepsize:t_end-t_0_die3;
y3=[zeros(1,size(x0,2)-size(x3,2)),(polyval(p32,x3)-polyval(p31,x3))/(pow34-pow31)*power3];
%Creating total sum vector
y_total=y1+y2+y3+Ta*ones(1,size(x0,2)); % Sum of curves from die1, die2 and die3
%plot
plot(x0,y_total)

Respuestas (1)

Titus Edelhofer
Titus Edelhofer el 23 de Feb. de 2016
Hi Jakob,
xlsread in the background opens Excel, reads the data and closes it. This takes some time, therefore I would suggest to read the data not one by one, but as one large block. Within your MATLAB code you then read portions (even in a loop, if you like). This should make everything easier and faster.
Titus
  1 comentario
Stephen23
Stephen23 el 24 de Feb. de 2016
Jakob's "Answer" moved here:
That I will try to do. Simple just read one time the qhole sheet and then read out inside matlab afterwards.

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