Info

This question is closed. Reopen it to edit or answer.

for loops are taking too much time for simulation of my problem. Here I am giving my part of the problem that how can i reduce time consume of for loop. Could anyone help me or edit my code for better performance. the code is running by large time

3 views (last 30 days)
%%this is code in which I have created a 729 no. of text files of each tmy_1,
%%tmy_1....tmy_729, tmz_1, tmz_2...., tmz_729, tjy_1, tjy_2...., tjy_729 and
%%tjz_1, tjz_2,......, tjz_729. Each text file consist of 2000 element.
%%then from the each text file the values are stored in tmyxp(1,1,m,n),
%%tmzxp(1,1,m,n), tjyxp(1,1,m,n), tjzxp(1,1,m,n) in parallel manner. means you can
%%understand from the code. Hence please anyone help me. it's being serious problem
%for me
% code
steps=20;
N1=zeros(1,steps);
a=zeros(1,steps);
a1=zeros(1,steps);
a2=zeros(1,steps);
a3=zeros(1,steps);
N2=zeros(1,steps);
N3=zeros(1,steps);
N4=zeros(1,steps);
for i=number_of_time_steps+1:steps
py=0;
py1=0;
py2=0;
py3=0;
for m=1:27
for n=1:27
py=py+1;
textFilename1=['tmy_' num2str(py) '.txt'];
fid=fopen(textFilename1,'r');
N1=fscanf(fid,'%f');
fclose(fid);
a=N1(1:steps);
tmyxp(1,1,m,n)= a(i);
py1=py1+1;
textFilename2=['tmz_' num2str(py1) '.txt'];
fid=fopen(textFilename2,'r');
N2=fscanf(fid,'%f');
fclose(fid);
a1=N2(1:steps);
tmzxp(1,1,m,n)= a1(i);
py2=py2+1;
textFilename3=['tjy_' num2str(py2) '.txt'];
fid=fopen(textFilename3,'r');
N3=fscanf(fid,'%f');
fclose(fid);
a2=N3(1:steps);
tjyxp(1,1,m,n)= a2(i);
py3=py3+1;
textFilename4=['tjz_' num2str(py3) '.txt'];
fid=fopen(textFilename4,'r');
N4=fscanf(fid,'%f');
fclose(fid);
a3=N4(1:steps);
tjzxp(1,1,m,n)= a3(i);
end
end
end

Answers (0)

This question is closed.

Community Treasure Hunt

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

Start Hunting!