Thanks to everyone who helped me with this issue.
I have re-written the program with the help of the MathWorks support team who suggested the use of in-build functions rather looping and this has brought down the runtime by ~98%.
I have shown my modified code below if in-case anyone needs it.
%% Import CAN Message and Database File for Message table creation
msgTable = canMessageImport('Msg.asc','vector',canDatabase(canDBC),'OutputFormat','timetable');
%% Time in the Message table is rounded to "1" decimal place to avoid odd timestamp in final table
msgTable.Time = seconds(round(seconds(msgTable.Time),1));
%% Signal Extraction from Message Table
Sig = canSignalTimetable(msgTable);
%% Assigning field names to a variable for looping through to synchronize or concatenate the signals
FieldNames = fields(Sig);
Data = Sig.(FieldNames{1});
%% Individual Signal tables are "synchronized" based on timestamp in loop
for i=2:length(FieldNames)
Data = synchronize(Data, Sig.(FieldNames{i}));
end
%% Replacing missing or NAN values to "-999"
Data = fillmissing(Data, 'Constant', -999);
Thanks.
7 Comments
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/501239-how-can-i-improve-code-efficiency#comment_788377
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/501239-how-can-i-improve-code-efficiency#comment_788377
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/501239-how-can-i-improve-code-efficiency#comment_788380
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/501239-how-can-i-improve-code-efficiency#comment_788380
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/501239-how-can-i-improve-code-efficiency#comment_788392
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/501239-how-can-i-improve-code-efficiency#comment_788392
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/501239-how-can-i-improve-code-efficiency#comment_788394
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/501239-how-can-i-improve-code-efficiency#comment_788394
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/501239-how-can-i-improve-code-efficiency#comment_788402
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/501239-how-can-i-improve-code-efficiency#comment_788402
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/501239-how-can-i-improve-code-efficiency#comment_788411
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/501239-how-can-i-improve-code-efficiency#comment_788411
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/501239-how-can-i-improve-code-efficiency#comment_788419
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/501239-how-can-i-improve-code-efficiency#comment_788419
Sign in to comment.