Filter löschen
Filter löschen

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

5 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Jaynik
Jaynik am 7 Mär. 2024
Bearbeitet: Jaynik am 7 Mär. 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.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by