Convert for loop with cells and polyarea into a cellfun function

1 vue (au cours des 30 derniers jours)
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;

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Elementary Polygons dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by