Matlab run and time export csv

Viewed 25

I am trying to run some code in matlab with "run and time" mode, which returns the amount of time each function has been running. Is there a way to export the output window (see image attached) as a csv file or something similar to visualize the data in a jupyter notebook, for example? Or is there another way to do it? Thanks!

enter image description here

1 Answers

To open the window you've shown, you would likely run profile viewer, to get the same info as a variable you can just run p = profile('info');. In both cases you would have started and stopped the timing using profile on;/profile off; respectively.

This gives you a struct which includes the FunctionTable field, which has all functions and their timing info.

Some of the table info is nested struct data or sub-times, you could remove these columns and then write to csv.

Complete example:

profile on;
% your code to time here
profile off;
p = profile('info');
tbl = p.FunctionTable(:,{'CompleteName','FunctionName','NumCalls','TotalTime'});
writetable( tbl, 'myTimingData.csv' );
Related