Reading data from CSV file takes too long any suggestion ?

clc
clear
tic
format long
files= dir('E:\PIV\*.csv');
num_files = length(files);
data_length = cell(1,num_files);
for(i=1:1:num_files);
%import all data from Column E to K
data_length{i} = xlsread(files(i).name,'E:K');
A = cell2mat(data_length);
i = 3:7:(num_files-1)*7+3;
j = 4:7:(num_files-1)*7+4;
k = sort([i j]);
%Remove two columns G and H
A(:,k)=[];
% defining mask area
r = 55/2;
p = r+2;
i = 1:5:(num_files-1)*5+1;
j = 2:5:(num_files-1)*5+2;
x = A(:,i);
y = A(:,j);
R = (x-p).^2+(y-p).^2<=r^2;
k = 5:5:(num_files-1)*5+5;
Le = A(:,k).*R;
Le(Le==0) = [];
x=A(:,i).*R;
x(x==0) = [];
y=A(:,j).*R;
y(y==0) = [];
standard_deviation_Le=std(Le);
k = 4:5:(num_files-1)*5+4;
velocity_v=A(:,k).*R;
velocity_v(velocity_v==0) = [];
positive_velocity_v=abs(velocity_v);
standard_deviation_v=std(positive_velocity_v);
k = 3:5:(num_files-1)*5+3;
velocity_u=A(:,k).*R;
velocity_u(velocity_u==0) = [];
positive_velocity_u=abs(velocity_u);
standard_deviation_u=std(positive_velocity_u);
TKE=0.5*(standard_deviation_u^2+standard_deviation_v^2+((standard_deviation_u+standard_deviation_v)/2)^2);
number=numel(x)/num_files;
%Averaging Velocity u
E=reshape(velocity_u,number,num_files);
E=E';
E=var(E);
%Averaging Velocity v
W=reshape(velocity_v,number,num_files);
W=W';
W=var(W);
%Averaging x
X=reshape(x,number,num_files);
X=X';
X=mean(X);
%Averaging y
Y=reshape(y,number,num_files);
Y=Y';
Y=mean(Y);
scale_factor = 0.1;
figure
quiver(X,Y,E*scale_factor,W*scale_factor,'AutoScale','off')
end

 Réponse acceptée

Walter Roberson
Walter Roberson le 5 Sep 2016
If you are using a version earlier than R2016a, then use xlsread1() from the File Exchange.

5 commentaires

i geet the following Error Error using evalin Undefined function or variable 'Excel'.
Error in xlsread1 (line 108) Excel = evalin('base','Excel'); % added command (Brandao 12/09/2008) and im using Matlab R2016a
R2016a has the speed-up built in, at least for MS Windows systems that have Excel installed. If you are not using an MS Windows system with Excel installed then you cannot use xlsread1() .
You might be able to use xlread() from the File Exchange, but it might not be any faster.
I do not understand your code. It appears to me that you have a missing 'end' after the xlsread line, to read all of the data in before you proceed to further processing. Some of the calculations you do just do not seem to make any sense otherwise.
I cannot tell from your code how many columns of data you have, or what the format of the columns is.
Yes there is an End i kinda removed it while was copying here, what i have in excel is A to L and what i want is E, F, I, J and K columns so i'm reading E to K and removing G and H, when i run the code to read all data its almost instant but when i say 'E:K' at the end it takes a long time even for 3 files (i have 1200 CSV files!!)
Sometimes the fastest approach is to read all of the data and throw away the parts you do not need.
Yes i guess you are right,

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by