submitWithConfiguration not working in matlab R2019b

15 次查看(过去 30 天)
Beforehand on previous versions of matlab my following code was working fine. However, after upgrading to latlab R2019b, i get the following error in the submitWithConfiguration function in which it says that 'parts function is not defined.
Here is my code
function submit()
addpath('./lib');
conf.assignmentSlug = 'logistic-regression';
conf.itemName = 'Logistic Regression';
conf.partArrays = { ...
{ ...
'1', ...
{ 'sigmoid.m' }, ...
'Sigmoid Function', ...
}, ...
{ ...
'2', ...
{ 'costFunction.m' }, ...
'Logistic Regression Cost', ...
}, ...
{ ...
'3', ...
{ 'costFunction.m' }, ...
'Logistic Regression Gradient', ...
}, ...
{ ...
'4', ...
{ 'predict.m' }, ...
'Predict', ...
}, ...
{ ...
'5', ...
{ 'costFunctionReg.m' }, ...
'Regularized Logistic Regression Cost', ...
}, ...
{ ...
'6', ...
{ 'costFunctionReg.m' }, ...
'Regularized Logistic Regression Gradient', ...
}, ...
};
conf.output = @output;
submitWithConfiguration(conf);
end
function out = output(partId, auxstring)
% Random Test Cases
X = [ones(20,1) (exp(1) * sin(1:1:20))' (exp(0.5) * cos(1:1:20))'];
y = sin(X(:,1) + X(:,2)) > 0;
if partId == '1'
out = sprintf('%0.5f ', sigmoid(X));
elseif partId == '2'
out = sprintf('%0.5f ', costFunction([0.25 0.5 -0.5]', X, y));
elseif partId == '3'
[cost, grad] = costFunction([0.25 0.5 -0.5]', X, y);
out = sprintf('%0.5f ', grad);
elseif partId == '4'
out = sprintf('%0.5f ', predict([0.25 0.5 -0.5]', X));
elseif partId == '5'
out = sprintf('%0.5f ', costFunctionReg([0.25 0.5 -0.5]', X, y, 0.1));
elseif partId == '6'
[cost, grad] = costFunctionReg([0.25 0.5 -0.5]', X, y, 0.1);
out = sprintf('%0.5f ', grad);
end
end
Following is the error i get
Unrecognized function or variable 'parts'.
Error in submitWithConfiguration (line 4)
parts = parts(conf);
Error in submit (line 40)
submitWithConfiguration(conf);
Please give me some suggestions as for how to solve this. Thanks for your time!
  18 个评论

请先登录,再进行评论。

采纳的回答

Bruno Luong
Bruno Luong 2019-9-22
编辑:Bruno Luong 2020-7-19
The problem is in the statement
parts = parts(conf);
In MATLAB 2019B, you cannot use the same name of variable and function, because the JIT will consider the PARTS as variable and overshadow your function.
This change is new for R2019B, please read the Release Note for more information.
In anycase use the same name for VARIABLE and FUNCTION is evidently a terrible way of programming (I see the same happens inside the body of PARTS function).
EDIT: Workaround If you are allowed to edit and make change of function submitWithConfiguration, change the LHS of line 4, AND successive instants of "parts" after this line to "part_variable".
part_variable = parts(conf); % Keep the "parts" on RHS
% ... also successive instant of "parts" to "part_variable" without double quote
  18 个评论
Ajay Kumar
Ajay Kumar 2021-4-27
'parts' requires one of the following:
Automated Driving Toolbox
Navigation Toolbox
Robotics System Toolbox
Sensor Fusion and Tracking Toolbox
UAV Toolbox
Error in submitWithConfiguration (line 4)
parts = parts(conf);
Error in submit (line 45)
submitWithConfiguration(conf);
makeValidFieldName
Not enough input arguments.
Error in makeValidFieldName (line 7)
pos=regexp(str,'^[^A-Za-z]','once');
submitWithConfiguration
Warning: Function Warning: Name is nonexistent or not a directory: /MATLAB Drive/machine-learning-ex1/machine-learning-ex1/ex1/lib/./lib/jsonlab
> In path (line 109)
In addpath (line 86)
In addpath (line 49)
In submitWithConfiguration (line 2)
Not enough input arguments.
Error in submitWithConfiguration (line 4)
partsfun = parts(conf);
i am still geting this error
Rik
Rik 2021-7-8
Comment posted as flag by Chandini pradhan:
part_variable = parts(conf); this is also not working .showing the same problem

请先登录,再进行评论。

更多回答(6 个)

Tom Mosher
Tom Mosher 2020-2-22
编辑:Tom Mosher 2020-2-22
I am a mentor for the Coursera "Machine Learning" course. I'm posting here in hopes that students of the course will stop using this thread.
  • Students should not modify their submit functions.
  • The course materials have been updated to address this issue.
  • There are separate programming exercise zip files for Octave and MATLAB Online. If you download the correct zip file, you won't have this problem.
If you are using MATLAB Online and see this "parts" = parts(conf)" error, it means you installed the wrong zip file.
  • The zip file for use with MATLAB Online is available via the Week 2 course materials page that has the MATLAB Online setup instructions. This zip file also includes the 'mlx' companion scripts that include the exercise instructions.
  • The zip file you find on the "Programming Assignments" page is only for use with Octave - or with older desktop MATLAB versions that don't support mlx files.
  12 个评论
Amirali Malekani Nezhad
It's not working. The 2021 submit files are not working sir. I tried Octave. I tried Matlab, I tried github versions, I tried your versions, None of them work and all fail in the submission part. I really don't know what else to try, none of your versions work.
Tom Mosher
Tom Mosher 2021-10-22
The MATLAB scripts work with MATLAB Online.
The Octave scripts work with Octave and with MATLAB r2019a and earlier.
Hundreds of thousands of students have used these programming assignments without problems.
Please post your questions about the course on the Coursera "Machine Learning" forum.

请先登录,再进行评论。


Guillaume
Guillaume 2019-9-22
What you're seeing is a documented change of behaviour in R2019b, regarding poorly written code as is the case here.
Matlab no longer accepts the same name being used for both a variable and a local function. See identifiers cannot be used for two purposes inside a function.
The simplest fix is to rename the parts function to partsfun or similar and do the same where it is called, so on line 4:
parts = partsfun(conf);
and on line 77:
function parts = partsfun(conf)
If that code was provided to you by your tutor, you're entitled to complain to them. They shouldn't give you code that has so many mlint warnings.
Even that parts function is poorly written:
function parts = partsfun(conf)
parts = num2cell(cell2struct(vertcat(conf.partArrays{:}), {'id', 'sourcefiles', 'name'}, 2))';
end
would produce the same output.
  5 个评论

请先登录,再进行评论。


Cesare Ressa
Cesare Ressa 2020-2-4
  4 个评论
Amirali Malekani Nezhad
I am using your own submission files sir. The UPDATED ones as you say. It DOES NOT work. It keeps giving errors. I have tried everything and quite frankly am out of ideas and really need help because I wish to complete the course but can't submit any of my assignments. Please assist me ASAP.
my email is sirmalek2018@gmail.com
Please email me or comment here asap.
Amirali Malekani Nezhad
Here is what I get
Running warmUpExercise ...
5x5 Identity Matrix:
ans =
Diagonal Matrix
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Program paused. Press enter to continue.
Plotting Data ...
Program paused. Press enter to continue.
Testing the cost function ...
With theta = [0 ; 0]
Cost computed = 32.072734
Expected cost value (approx) 32.07
With theta = [-1 ; 2]
Cost computed = 54.242455
Expected cost value (approx) 54.24
Program paused. Press enter to continue.
Running Gradient Descent ...
Theta found by gradient descent:
-3.630291
1.166362
Expected theta values (approx)
-3.6303
1.1664
warning: legend: ignoring extra labels.
warning: called from
legend>parse_opts at line 817 column 9
legend at line 206 column 8
ex1 at line 88 column 1
For population = 35,000, we predict a profit of 4519.767868
For population = 70,000, we predict a profit of 45342.450129
Program paused. Press enter to continue.
Visualizing J(theta_0, theta_1) ...
>>
>> submit
warning: load_path: lib\jsonlab: No such file or directory
warning: load-path: update failed for 'lib\jsonlab', removing from path
warning: load_path: lib\jsonlab: No such file or directory
warning: called from
submit at line 2 column 3
warning: load-path: update failed for 'lib\jsonlab', removing from path
warning: called from
submit at line 2 column 3
warning: addpath: ./lib/jsonlab: No such file or directory
warning: called from
submitWithConfiguration at line 2 column 3
submit at line 45 column 3
warning: load_path: lib\jsonlab: No such file or directory
warning: called from
submitWithConfiguration at line 2 column 3
submit at line 45 column 3
warning: load-path: update failed for 'lib\jsonlab', removing from path
warning: called from
submitWithConfiguration at line 2 column 3
submit at line 45 column 3
== Submitting solutions | Linear Regression with Multiple Variables...
Login (email address): *******@gmail.com
Token: *******
warning: load_path: lib\jsonlab: No such file or directory
warning: called from
submitWithConfiguration>makePartsStruct at line 85 column 15
submitWithConfiguration>makePostBody at line 76 column 20
submitWithConfiguration>submitParts at line 65 column 8
submitWithConfiguration at line 22 column 14
submit at line 45 column 3
warning: load-path: update failed for 'lib\jsonlab', removing from path
warning: called from
submitWithConfiguration>makePartsStruct at line 85 column 15
submitWithConfiguration>makePostBody at line 76 column 20
submitWithConfiguration>submitParts at line 65 column 8
submitWithConfiguration at line 22 column 14
submit at line 45 column 3
warning: load_path: lib\jsonlab: No such file or directory
warning: called from
submitWithConfiguration>makePartsStruct at line 85 column 15
submitWithConfiguration>makePostBody at line 76 column 20
submitWithConfiguration>submitParts at line 65 column 8
submitWithConfiguration at line 22 column 14
submit at line 45 column 3
warning: load-path: update failed for 'lib\jsonlab', removing from path
warning: called from
submitWithConfiguration>makePartsStruct at line 85 column 15
submitWithConfiguration>makePostBody at line 76 column 20
submitWithConfiguration>submitParts at line 65 column 8
submitWithConfiguration at line 22 column 14
submit at line 45 column 3
!! Submission failed: 'makeValidFieldName' undefined near line 85, column 85
Function: submitWithConfiguration>makePartsStruct
FileName: C:\Users\elmm\Desktop\Andrew Ng Machine Learning Assignments\NOO\lib\submitWithConf
iguration.m
LineNumber: 85
Please correct your code and resubmit.
>>

请先登录,再进行评论。


Tom Mosher
Tom Mosher 2020-5-2
I am a mentor for Andrew Ng's Machine Learning course.
The recommended fix for this issue is to use the correct set of programming exercise scripts.
There are two sets:
  • One for Octave (it's in the "Programming Assignment" page).
  • The other is for MATLAB 2019b and later - like MATLAB Online. It has the fix required for this "parts = parts(conf)" issue. The MATLAB version of the programming exercise scripts is on the page in Week 2 with the MATLAB Online setup instructions.
***** Other benefits of using the right set of scripts *****
If you get the MATLAB version of the programming exercise scripts, you also get the ".mlx" helper script file, with the built-in instructions and fancy Notebooks-like interface. That is not provided with the Octave version of the scripts.
You also get all eight programming exercises in one swipe- with Octave, you have to repeat the download-and-extract business eight times during the course.
********
So, please use the right programming exercise scrips - and stop modifying the submit functions. Many students break things when trying that. It's a bad day for everyone.
Thank you.
  9 个评论

请先登录,再进行评论。


Tom Mosher
Tom Mosher 2020-8-31
I request that the OP of this thread please close it to further comments.
The question has been answered multiple times.
  4 个评论
Swarrangi P
Swarrangi P 2020-10-9
Even after following all the steps im not able to submit it.
Tom Mosher
Tom Mosher 2020-10-9
If you have problems with the course assignments, please post on the course Discussion Forum - not here.

请先登录,再进行评论。


kapil vaishnav
kapil vaishnav 2021-8-16
Submission failed: unexpected error: Unrecognized field name "assignmentSlug".
how to solve this?
  3 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Historical Contests 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by