How to speed up this code?
12 次查看(过去 30 天)
显示 更早的评论
Hi all,
I have several CANBUS .ASC files that I have to convert to .MAT files for further analysis. In particolar, I need a struct which contains some specified signals where the list is contained in a variable called Signals2Load, which in turn they are contained in a list of messages named Message2Load. Due to the fact that the functions canSignalImport and canSignalTimetable do not work (I am in contact the MathWorks support for this), I had to create my own code. Below, you will find the code. Unfortunately, it is pretty slow for a 1h log (more than 3e6 messages to analyse), it takes almost two hours for the conversion. What could I do for speeding up the code?
Thanks.
Best regards,
Michele
message=canMessageImport([ASCFiles(iASC).folder '\' ASCFiles(iASC).name],'Vector',candb,'OutputFormat','timetable');
messageStruct=table2struct(message);
Duration=floor(seconds(message.Time(end)));
CanData(iASC).Time=[0:DT:Duration];
Message2Sel=find(contains({messageStruct.Name},Message2Load));
if length(unique({messageStruct(Message2Sel).Name}))~=length(Message2Load)
warning(['The following messages were not found ']);
setdiff(Message2Load,unique({messageStruct(Message2Sel).Name}))
end
for i=1:length(Message2Sel)
Sig=fieldnames(messageStruct(Message2Sel(i)).Signals);
[Sig2Sel iSig2Load iSig]=intersect(Signals2Load,Sig);
if isempty(iSig2Load)==0
for iSigFound=1:length(Sig2Sel)
Sigs{iSig2Load(iSigFound)}=[Sigs{iSig2Load(iSigFound)}; messageStruct(Message2Sel(i)).Signals.(Sig{iSig(iSigFound)})];
Time{iSig2Load(iSigFound)}=[Time{iSig2Load(iSigFound)}; seconds(message.Time(Message2Sel(i)))];
end
end
end
7 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Performance and Memory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!