How to calculate center of pressure given a 2d array containing pressure data
조회 수: 29 (최근 30일)
이전 댓글 표시
So as the title says I want to know how to calculate the center of pressure coordinates given that the input will be a 2d matrix with each element representing a "pressure grid".
댓글 수: 3
the cyclist
2024년 3월 13일
편집: the cyclist
2024년 3월 13일
Do elements with index 1,2,3 ... representing points that are equally spaced in the "real world"? Is the spacing the same along the two dimensions?
채택된 답변
the cyclist
2024년 3월 13일
편집: the cyclist
2024년 3월 13일
If the answers to both of the questions in my comment is "yes", then
% Example input
pressureArray = [1 2 3;
4 5 6;
7 8 9]
% Get array size
[rows, cols] = size(pressureArray);
% Total pressure
totalPressure = sum(pressureArray,"all");
% Calculate moments about x and y axes
momentX = sum((1:cols) .* pressureArray,"all");
momentY = sum((1:rows)' .* pressureArray,"all");
% Calculate center of pressure
COP_x = momentX / totalPressure
COP_y = momentY / totalPressure
The "spatial" coordinates are the indexing of the array (in this case 1:3 along both directions). You may need to apply a multiplier, or translation operation.
추가 답변 (1개)
Image Analyst
2024년 3월 14일
If you have the Image Processing Toolbox (I think most people do) then you can do it in one line of code by asking regionprops to compute the weighted centroid.
% Example input from the cyclist
pressureArray = [1 2 3;
4 5 6;
7 8 9];
% Using regionprops to compute the weighted centroid. Requires Image Processing Toolbox.
props = regionprops(true(size(pressureArray)), pressureArray, 'WeightedCentroid')
댓글 수: 2
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!