Does loading a table in a subfunction I'm calling slow my routine down?
Show older comments
I have a script which contains a function that calls a sub-function many times, where the sub-function analyzes data from a large, read-only 8000 x 5 table that never changes. I load the table at the beginning of the sub-function. Question: am I slowing down my script dramatically by re-loading the same data each time I call the sub function? Is there a better way to do this? Simplified code below:
**********myfun.m********************
function tt = myfun(z)
i = 1;
sum_one = 0;
sum_two = 0;
for i = 1:z;
t = mysubfun(i);
sum_one = sum_one + t(1,1)
sum_two = sum_two + t(1,2)
end
tt = table(sum_one, sum_two)
end
***********mysubfun.m*******************
function t = mysubfun(x)
load('data.mat') %loads a table that is 8000 x 5
t = table(sum(data(1:x,1),sum(data(1:x,2))
end
Accepted Answer
More Answers (0)
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!