Filling missing values of a table with previous interpolation and improving the code performance
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Guillaume
am 25 Apr. 2019
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.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!