Problem in "Increasing Automation with Functions > Creating and Calling Functions > (5/5) Create and Call Local Function", Task 2, MatLab Fundamentals
11 次查看(过去 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
0 个评论
采纳的回答
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 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!