MATLAB Answers

Rui
0

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

Asked by Rui
on 22 Oct 2018
Latest activity Answered by Walter Roberson
on 22 Oct 2018
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?

  0 Comments

Sign in to comment.

1 Answer

Answer by Walter Roberson
on 22 Oct 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.

  0 Comments

Sign in to comment.