Convert for loop with cells and polyarea into a cellfun function

1 回表示 (過去 30 日間)
Alejandro Fernández
Alejandro Fernández 2021 年 1 月 31 日
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 Center および File ExchangeElementary Polygons についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by