Borrar filtros
Borrar filtros

Problem in "Increasing Automation with Functions > Creating and Calling Functions > (5/5) Create and Call Local Function", Task 2, MatLab Fundamentals

5 visualizaciones (últimos 30 días)
I have reached the Task 2 but I'm not finding what's wrong. My script is:
function pp = paretoperc(medals)
ppgold = paretoperc(golds);
% Cumulative contribution of data points (in order)
cc = cumsum(sort(medals(:),"descend")); % (:) to ensure column vector
cc = 100*cc/cc(end); % Normalize to percentage
% Corresponding percentiles (column vector to match cc)
pct = (1:numel(medals))';
pct = 100*pct/numel(pct); % Normalize to percentage
% Find the number of data values needed so that
% P% of the data is in (100-P)% of the values
idx = find(cc >= (100-pct),1,"first");
pp = cc(idx);
end

Respuesta aceptada

Jaynik
Jaynik el 7 de Mzo. de 2024
Editada: Jaynik el 7 de Mzo. de 2024
Hi Luciano,
The way you have calculated the value of "ppgold" is correct but you have written it within the function definition of "paretoperc". You just need to call the function and assign it to "ppgold" instead of adding it inside the function and writing the entire function again. Note that you cannot have the same function definition twice and you need to define the function at the end of the file to use it twice.

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by