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

1 回表示 (過去 30 日間)
Sam17
Sam17 2019 年 4 月 24 日
コメント済み: Guillaume 2019 年 4 月 25 日
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 Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by