why does the syntax for retriving data from table influences the speed up to 10x ?

1 Ansicht (letzte 30 Tage)
tic
for i = 1: 8640
startVctn_str = ferias1{1, k*3};
endVctn_str = ferias1{1, k*3+1};
end
toc
tic
for i = 1: 8640
startVctn_str = ferias1.s1(1,:);
endVctn_str = ferias1.e1(1, :);
end
toc
tic
for i = 1: 8640
startVctn_str = ferias1.(k*3)(1,:);
endVctn_str = ferias1.(k*3+1)(1, :);
end
toc
Elapsed time is 0.798681 seconds.
Elapsed time is 0.091542 seconds.
Elapsed time is 1.089919 seconds.
'ferias' is a table and i want to access the columns indexes which are multiples of 3 and retrieve the correspondent string. my table is fairly big so it was getting a little slow and i profile the code, which showed these calls were the culprit. Ideally i wanna use the dot syntax 'ferias1.s1', but that way I'll have to name every single column, which is not doable. What syntax should i use to be faster?

Antworten (1)

Walter Roberson
Walter Roberson am 22 Okt. 2018
t = ferias(:,3:3:end);
tcell = t{:,:};
tcell would be a cell array of character vectors, with as many rows as ferias has rows, and as many columns as number of columns of ferias divided by 3.

Kategorien

Mehr zu Tables 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!

Translated by