How to select multiple rows from an array and apply some operation iteratively
조회 수: 1 (최근 30일)
이전 댓글 표시
This is an array with 324 Rows and 3 Columns. I want to select patch of 3 rows as (Row1= P1, Row2= P2 and Row3= P3), then apply some operation and then select next three rows as (Row4= P4, Row5= P5 and Row6= P6) apply the same operation, and so on........... Finally I want to take the sum of all the individual operations applied.
I assume that I should use for loop to get this operation done, but I'm confused!!!!!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/728924/image.png)
For more assistance with the question: Actually P1, P2 and P3 will be used as vertices coordinated of a triangle, and I want to calculate the area of all triangles.
The function I am using to find area is: Triangle Area and Angles
댓글 수: 0
채택된 답변
Matt J
2021년 9월 3일
편집: Matt J
2021년 9월 3일
Well, the efficient way to do the area calculation specifically is,
A=T(1:3:end,:).';
B=T(2:3:end,:).';
C=T(3:3:end,:).';
Areas=abs(cross(B-A,C-A))/2;
To do general operations on blocks of 3 rows, you could use mat2tiles from,
out = cellfun(@triangle_areas, mat2tiles(T,[3,3]) )
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!