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

5 次查看(过去 30 天)
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

采纳的回答

Jaynik
Jaynik 2024-3-7
编辑:Jaynik 2024-3-7
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by