Filling missing values of a table with previous interpolation and improving the code performance

조회 수: 4 (최근 30일)
I wrote the variables I want to interpolate in excel sheet and imported the excel in matlab and wrote these lines of code. My code works but it takes so much of time may be because my file size is big. Is there any way I can rewrite this code and make it more simpler and less time and memory consuming ?
[FileName,PathName] = uigetfile('*.xls*','Select excel file');
[~,~,interpolate] = xlsread(strcat(PathName,FileName));
interpolate = interpolate(2:end,2)';
variables=Total_Data.Properties.VariableNames;
to_delete= interpolate(2:end);
index=find(ismember(variables,to_delete));
Total_Data(:,index)=[];
index=find(ismember(variables,interpolate));
Data=Total_Data(:,index);
Data = fillmissing(Data,'previous');
Total_Data = outerjoin(Total_Data,Data,'MergeKeys',true);
  댓글 수: 1
Guillaume
Guillaume 2019년 4월 25일
As I mentioned in your other question, it would be useful to know which part of your code is the bottleneck, something that only you can answer by profiling your code.
In addition, your code would benefit greatly of comments explaining what it's meant to do. In particular, the bit
variables=Total_Data.Properties.VariableNames;
to_delete= interpolate(2:end);
index=find(ismember(variables,to_delete));
Total_Data(:,index)=[];
index=find(ismember(variables,interpolate));
Data=Total_Data(:,index);
If that bit doesn't error on that last line you're lucky, or perhaps unlucky since in that case it most likely doesn't return the intended result as you use the index of columns as they were before you deleted some of them.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by