MATLAB Fundamentals course problem creating a local function

조회 수: 32 (최근 30일)
Ajit Singh
Ajit Singh 2022년 3월 13일
댓글: Renee Coetsee 2023년 6월 15일
Hi , I was trying to complete the MATLAB fundamentals course and I encountered a probel in chapter 15 .1 last part "Create and call a local function" . I followed the isntructions and my answer was just like the solution provided , I even tried copy pasting the solution cell-wise but the answer cannot pass the last test, i.e., "Is pp calculated from the function paretoperc?" . Someone please help me with it. I skipped it for now and completed the rest of the course and now my progress is stuck at 99%.
  댓글 수: 3
Ajit Singh
Ajit Singh 2022년 3월 13일
Thankyou, I am attaching the screenchot the the page, help me figure out how to pass the last test.
SANJEEV PERUMAL R S
SANJEEV PERUMAL R S 2023년 5월 25일
use this -
pp=paretoperc(medals)

댓글을 달려면 로그인하십시오.

답변 (3개)

Renee Coetsee
Renee Coetsee 2022년 3월 15일
편집: Renee Coetsee 2022년 3월 15일
There is an issue with this task. You can resolve the issue by adding clear in the very first line of the script.
More information can be found here:
  댓글 수: 13
Ibrahim
Ibrahim 2023년 6월 15일
Hi Renee. Please find attached
Renee Coetsee
Renee Coetsee 2023년 6월 15일
Hi Ibrahim, thanks for sharing your code.
You created the function correctly but you also need to use the function by adding this line of code above the function:
pp = paretoperc(medals);
If you click "See Solution" you can see the whole script. I hope this helps!

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2022년 3월 13일
편집: Image Analyst 2022년 3월 13일
Maybe it really wants "medals" (like it said) for the input argument rather than "x" like you put.
Attach your code if you want us to run it. (I don't want to type all that in.)
  댓글 수: 3
Ajit Singh
Ajit Singh 2022년 3월 13일
load medalcounts bronzes silvers golds medals
histogram(medals)
xlabel("Medal count")
ylabel("Number of teams")
paretoperc(medals);
function pp = paretoperc(medals)
% 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
Ajit Singh
Ajit Singh 2022년 3월 13일
편집: Ajit Singh 2022년 3월 13일
the contents of medal were the follwoing , (I don't know how to save that file to my pc so I copied it from the workspace)
113
88
58
65
71
46
36
33
37
40
24
21
20
15
20
20
14
11
10
8
9
17
9
13
11
8
7
9
7
6
5
5
8
12
13
4
4
3
4
4
3
2
2
19
7
4
4
7
6
4
4
3
7
6
5
4
4
2
2
2
2
2
1
1
1
5
7
5
4
3
4
3
3
2
2
2
1
1
1
1
1
1
8
4
2
1
1
1
1
1
1
1
1

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2022년 3월 13일
You need to give us medalcounts
load medalcounts bronzes silvers golds medals % Load them in.
% Now save them out.
save('medalcounts.mat', 'bronzes', 'silvers', 'golds', 'medals');
then attach it with the paperclip icon.
  댓글 수: 4
Image Analyst
Image Analyst 2022년 3월 13일
I guess you would have to dl
load medalcounts bronzes silvers golds medals % Load them in.
% Now save them out to a file in the local C drive root folder.
save('c:\medalcounts.mat', 'bronzes', 'silvers', 'golds', 'medals');
Anyway, glad it's working.
Steven Lord
Steven Lord 2022년 3월 14일
The first sentence of the task states "Make the code in the Task 1 section into a local function called paretoperc, where medals is the input and pp is the output." Originally you had created a local function paretoperc and had it accept an input named medals, but your function call did not assign its output to a variable named pp. In your most recent attempt you added the missing output argument.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by