Table values extraction and consequent calculation

조회 수: 1 (최근 30일)
Vasileios Papavasileiou
Vasileios Papavasileiou 2022년 5월 16일
편집: Vasileios Papavasileiou 2022년 5월 17일
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.
cyclefirst = [Test_1_cycling.x_LINDT_Load_Cent_(1:39), Test_1_cycling.x_LINDT_LDT035_Cent_(1:39)];
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
Benjamin Kraus 2022년 5월 16일
편집: Benjamin Kraus 2022년 5월 16일
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;
cyclefirst = [Test_1_cycling.x_LINDT_Load_Cent_(range), Test_1_cycling.x_LINDT_LDT035_Cent_(range)];
A_loop(n) = polyarea(cyclefirst(:,1),cyclefirst(:,2));
end
  댓글 수: 3
Benjamin Kraus
Benjamin Kraus 2022년 5월 16일
That will teach me not to post code without running it first.
My range_start was missing a +1 so it was starting at 0. I've fixed it in the code in my previous post.
In cases like this, I highly recommend running the debugger on your code to see why you are getting the error message you are getting. For some tips using the debugger, check this documentation page.
This page has an animated GIT that shows how to set a breakpoint (scroll up a bit after clicking the link).
And this MATLAB Answer shows how to investigate the value of variables while you are debugging.
Vasileios Papavasileiou
Vasileios Papavasileiou 2022년 5월 17일
편집: Vasileios Papavasileiou 2022년 5월 17일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by