Convert for loop with cells and polyarea into a cellfun function

1 次查看(过去 30 天)
Hi, I was wondering if it would be possible to convert those lines of code of the for loop into the same expression but using the function cellfun
for i = 1 : length(dataOUT)
area(i,1) = polyarea(dataOUT{i}(:,1),dataOUT{i}(:,2));
end
[~,idx_cluster] = max(area);
Just for this example, dataOUT could be:
p = linspace(0,2.*pi,9);
x = 1.2*cos(p)';
y = 1.2*sin(p)';
dataOUT{1}(:,1) = x;
dataOUT{1}(:,2) = y;

采纳的回答

Walter Roberson
Walter Roberson 2021-1-31
area = cellfun(@(DO) polyarea(DO(:,1), DO(:,2)), dataOut);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Elementary Polygons 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by