Convert for loop with cells and polyarea into a cellfun function

1 Ansicht (letzte 30 Tage)
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;

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Elementary Polygons finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by