MATLAB Fundamentals course problem creating a local function

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 件のコメント

Image Analyst
Image Analyst 2022 年 3 月 13 日
編集済み: Image Analyst 2022 年 3 月 13 日
OK, we'll help. What can we do (short of doing the whole course to get to chapter 15)?
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 日

2 投票

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 件のコメント

Renee Coetsee
Renee Coetsee 2022 年 3 月 17 日
This issue should be fixed now. You should no longer need to add clear to pass the tests.
Chrysolite Dhinakaran
Chrysolite Dhinakaran 2022 年 6 月 6 日
I'm still running into this issue for 8.1 Project - Halfway Review of Fundamentals (Women's 200m Backstroke). I'm using the exact same code as the solution and it's not working.
Renee Coetsee
Renee Coetsee 2022 年 6 月 6 日
Hi Chrysolite, I just tried completing the 8.1 Project using the solution code and I was able to pass all the tests. To help me reproduce this issue, please provide the following information:
  • Which Task are you unable to complete?
  • Which assessment is failing?
  • What is the full URL of the activity? There is version information in the URL.
  • Can you post a screenshot of the full live script and any errors you are getting in the script?
You can try copying the entire solution script into the active script, not just the code for that Task.
Chrysolite Dhinakaran
Chrysolite Dhinakaran 2022 年 6 月 6 日
編集済み: Chrysolite Dhinakaran 2022 年 6 月 6 日
I tried it again and it just worked! Thanks for your quick response though!
MANINDER CHOUDHARY
MANINDER CHOUDHARY 2023 年 3 月 18 日
I'm facing the same problem. I have tried the different techniques but still the problem is unresloved.
Renee Coetsee
Renee Coetsee 2023 年 3 月 20 日
Hi Maninder, I'm not sure which activity is having a problem so I just tried 15.1 and 8.1. I wasn't able to reproduce any issues. Can you please provide the details in my previous comment?
  • Which Task are you unable to complete?
  • Which assessment is failing?
  • What is the full URL of the activity? There is version information in the URL.
  • Can you post a screenshot of the full live script and any errors you are getting in the script?
Sibusiso Mahlangu
Sibusiso Mahlangu 2023 年 4 月 10 日
Greetings. I am encountering the same issue for 15.1 and code is refusing to run. Please assist.
Sibusiso Mahlangu
Sibusiso Mahlangu 2023 年 4 月 10 日
The failing function is "Is pp calculated from the function paretoperc"?
Renee Coetsee
Renee Coetsee 2023 年 4 月 10 日
Hi Sibusiso, what is the full URL of the activity? There is version information in the URL that I need to investigate the issue.
Ibrahim
Ibrahim 2023 年 6 月 14 日
Hi. I'm running into the same issue.
Renee Coetsee
Renee Coetsee 2023 年 6 月 14 日
Hi Ibrahim, I am not seeing any problems at that link. I tested both tasks.
Can you post a screenshot of the full live script and any errors you are getting in the script?
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 日

0 投票

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 日
No that does not work I tried it.
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 日

0 投票

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 件のコメント

Ajit Singh
Ajit Singh 2022 年 3 月 13 日
Hi, I ran that in a cell and it might have gotten saved but not on my pc , as the course is online the files and workspace must be in their online repository somewhere. I even tried to open workspace and right click to save as , hoping it will allow me to download but the save location was in online somewhere, definitely not on my PC.
Ajit Singh
Ajit Singh 2022 年 3 月 13 日
Also thankyou very much for trying to help me, I really appreciate it. And just now the test passed , I don't understand all I did now was just the same, I just reset it and edited the task just like I did ealrier 4-5 times and the code was exaclty the same as above, the onlly change from above code is the using medals which cannot be the solution as I have tried it earlier too. I am attaching the code that worked for refernce. See if you can tell what might have been the issue.
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.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

製品

質問済み:

2022 年 3 月 13 日

コメント済み:

2023 年 6 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by