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

11 visualizzazioni (ultimi 30 giorni)
Luciano Manuel il 26 Feb 2024
Commentato: Luciano Manuel il 9 Mar 2024
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
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Jaynik il 7 Mar 2024
Modificato: Jaynik il 7 Mar 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.
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Luciano Manuel il 9 Mar 2024
Hi Jaynik,
Thanks a lot! Now I can complete the course.
Best wishes,
Manuel

Accedi per commentare.

### Categorie

Scopri di più su Graphics Object Programming in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by