# Table values extraction and consequent calculation

1 view (last 30 days)
Hey,
I have a 16001x11 table and what I want to do is to choose two columns and extract every 39 values of the column, perform a calculation (find the area in this case) and continue for the next set of 39 values for the entire height of the column.
Here is for example what I did for the first set of values.
A_loop = polyarea(cyclefirst(:,1),cyclefirst(:,2));
It works just fine, but I am struggling on finding a way to do the same for the entire height of the table, by simply perorming the same calculation for every 39 parameters.
Any ideas would be much appreciated.

Benjamin Kraus on 16 May 2022
Edited: Benjamin Kraus on 16 May 2022
Would a for loop do what you need? Something like this:
h = height(Test_1_cycling);
n = ceil(h/39);
A_loop = NaN(n,1);
for i = 1:n
range_start = (i-1)*39+1;
range_end = min(range_start+38,h);
range = range_start:range_end;
A_loop(n) = polyarea(cyclefirst(:,1),cyclefirst(:,2));
end
Vasileios Papavasileiou on 17 May 2022
Thanks, now it works as I wanted. Just a small detail needs to be changed to avoid any confussions, "A_loop(n)" should be "A_loop(i)", otherwise only the last value is returned.
You can also edit it in your code if you like.