Hi everybody, Please i have this code that load data too long time, i want to read it fastly(reduce time execution), somebody can i help me?
%Data is the 381x247x3 matrix; if true
LastGood = floor((122.5 - 50) / Header.Fstep) + 1 - 1; % value =29
FirstGood = ceil((140 - 50) / Header.Fstep) + 1 + 1; % value =38
disp(LastGood); % value =29
disp(FirstGood); % value =38
disp(size(Data, 2)); % value =247
for(k = 1:size(Data, 2))
InterpolazioneReale1 = fit(cat(2,[1:LastGood],[FirstGood:381])',cat(1,real(Data(1:LastGood,k,1)),real(Data(FirstGood:end,k,1))),'splineinterp');
InterpolazioneReale2 = fit(cat(2,[1:LastGood],[FirstGood:381])',cat(1,real(Data(1:LastGood,k,2)),real(Data(FirstGood:end,k,2))),'splineinterp');
InterpolazioneReale3 = fit(cat(2,[1:LastGood],[FirstGood:381])',cat(1,real(Data(1:LastGood,k,3)),real(Data(FirstGood:end,k,3))),'splineinterp');
InterpolazioneImmaginaria1 = fit(cat(2,[1:LastGood],[FirstGood:381])',cat(1,imag(Data(1:LastGood,k,1)),imag(Data(FirstGood:end,k,1))),'splineinterp');
InterpolazioneImmaginaria2 = fit(cat(2,[1:LastGood],[FirstGood:381])',cat(1,imag(Data(1:LastGood,k,2)),imag(Data(FirstGood:end,k,2))),'splineinterp');
InterpolazioneImmaginaria3 = fit(cat(2,[1:LastGood],[FirstGood:381])',cat(1,imag(Data(1:LastGood,k,3)),imag(Data(FirstGood:end,k,3))),'splineinterp');
Data(LastGood + 1:FirstGood - 1,k,1) = InterpolazioneReale1(LastGood + 1:FirstGood - 1) + i * InterpolazioneImmaginaria1(LastGood + 1:FirstGood - 1);
Data(LastGood + 1:FirstGood - 1,k,2) = InterpolazioneReale2(LastGood + 1:FirstGood - 1) + i * InterpolazioneImmaginaria2(LastGood + 1:FirstGood - 1);
Data(LastGood + 1:FirstGood - 1,k,3) = InterpolazioneReale3(LastGood + 1:FirstGood - 1) + i * InterpolazioneImmaginaria3(LastGood + 1:FirstGood - 1);
end
end

댓글 수: 6

per isakson
per isakson 2017년 10월 10일
편집: per isakson 2017년 10월 10일
Make a minimal working example, MWE. This MWE should focus one your question.
We cannot run your m-files without the m-files called, data files and furthermore we don't know what speed you expect.
KSSV
KSSV 2017년 10월 10일
It depends on what data your text file has....post your text file....to get help.
per isakson
per isakson 2017년 10월 10일
편집: per isakson 2017년 10월 10일
"loadind data loop fastly" How do you currently load/read the data files? Your way might be as fast as it gets.
Rik
Rik 2017년 10월 10일
Sometimes you can even wee it in task manager: if your disk load is 100%, further optimizing your code will not yield any benefit.
Jan
Jan 2017년 10월 10일
편집: Jan 2017년 10월 10일
Note:
cat(2,[1:LastGood],[FirstGood:381])'
can be simplified to:
[1:LastGood, FirstGood:381]'
Then store this in a variable instead of creating it 6 times.
Performing 6 spline fits for the same locations seems rather inefficient. Could this be simplified?
denis bertin
denis bertin 2017년 10월 10일
편집: denis bertin 2017년 10월 10일
Hi JAN SIMON, Yes, could be simplified, but i don't know how! I changed cat(2,[1:LastGood],[FirstGood:381])' to one variable [1:LastGood, FirstGood:381]', there is just a few change performance.
Thank you.

댓글을 달려면 로그인하십시오.

 채택된 답변

OCDER
OCDER 2017년 10월 10일
편집: OCDER 2017년 10월 10일

0 개 추천

Not sure if this is faster or not, but your code could be simplified a lot. If you have parallel computing toolbox, you could divide slow jobs across N cores.
LastGood = floor((122.5 - 50) / Header.Fstep) + 1 - 1; % value =29
FirstGood = ceil((140 - 50) / Header.Fstep) + 1 + 1; % value =38
disp(LastGood); % value = 29
disp(FirstGood); % value = 38
disp(size(Data, 2));% value = 247
X = [1:LastGood, FirstGood:381]';
parfor z = 1:3
Tdata = Data(:, :, z);
for k = 1:size(Tdata, 2) %Or do parfor here instead
InterpReal = fit(X, real(Tdata(X, k)), 'splineinterp');
InterpImag = fit(X, imag(Tdata(X, k)), 'splineinterp');
Range = LastGood + 1:FirstGood - 1;
Tdata(Range, k) = InterpReal(Range) + 1j * InterpImag(Range); %NOTE: 1j is now sqrt(-1)
end
Data(:, :, z) = Tdata;
end

댓글 수: 2

denis bertin
denis bertin 2017년 10월 11일
Many Thank's DONALD LEE.
OCDER
OCDER 2017년 10월 11일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2017년 10월 10일

댓글:

2017년 10월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by