submitWithConfiguration not working in matlab R2019b

476 views (last 30 days)
Umang Patel
Umang Patel on 22 Sep 2019
Commented: Tom Mosher on 26 Oct 2021
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!
  10 Comments

Sign in to comment.

Accepted Answer

Bruno Luong
Bruno Luong on 22 Sep 2019
Edited: Bruno Luong on 19 Jul 2020
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 Comments
Rik
Rik on 8 Jul 2021
Comment posted as flag by Chandini pradhan:
part_variable = parts(conf); this is also not working .showing the same problem

Sign in to comment.

More Answers (9)

Guillaume
Guillaume on 22 Sep 2019
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 Comments

Sign in to comment.


Tom Mosher
Tom Mosher on 22 Feb 2020
Edited: Tom Mosher on 22 Feb 2020
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 Comments
Tom Mosher
Tom Mosher on 22 Oct 2021
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.

Sign in to comment.


Cesare Ressa
Cesare Ressa on 4 Feb 2020
  4 Comments
Amirali Malekani Nezhad
Amirali Malekani Nezhad on 22 Oct 2021
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.
>>

Sign in to comment.


Tom Mosher
Tom Mosher on 2 May 2020
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 Comments

Sign in to comment.


Mehrdad Abdi
Mehrdad Abdi on 22 Sep 2019
I have the same problem in Matlab Online:
>> submit
Warning: Function Warning: Name is nonexistent or not a directory: /MATLAB Drive/machine-learning-ex1/machine-learning-ex1/./lib
> In path (line 109)
In addpath (line 86)
In addpath (line 47)
In submit (line 2)
Warning: Function Warning: Name is nonexistent or not a directory: /MATLAB Drive/machine-learning-ex1/machine-learning-ex1/./lib/jsonlab
> In path (line 109)
In addpath (line 86)
In addpath (line 47)
In submitWithConfiguration (line 2)
In submit (line 45)
'parts' requires one of the following:
Navigation Toolbox
Robotics System Toolbox
Sensor Fusion and Tracking Toolbox
Error in submitWithConfiguration (line 4)
parts = parts(conf);
Error in submit (line 45)
submitWithConfiguration(conf);
>> which parts -all
'parts' not found.
  6 Comments

Sign in to comment.


Ishita Biswas
Ishita Biswas on 4 Jun 2020
I am not able to fixed it what can do ? Please give a set of instruction.
>>submit
'parts' requires one of the following:
Automated Driving Toolbox
Navigation Toolbox
Robotics System Toolbox
Sensor Fusion and Tracking Toolbox
Error in submitWithConfiguration (line 4)
parts = parts(conf);
Error in submit (line 45)
submitWithConfiguration(conf);
  4 Comments
Walter Roberson
Walter Roberson on 9 Apr 2021
We do not know which version of the code you are using, so we do not know which line is line 38 in your version. Also you did not post a copy of the error message.

Sign in to comment.


Tom Mosher
Tom Mosher on 31 Aug 2020
I request that the OP of this thread please close it to further comments.
The question has been answered multiple times.
  4 Comments
Tom Mosher
Tom Mosher on 9 Oct 2020
If you have problems with the course assignments, please post on the course Discussion Forum - not here.

Sign in to comment.


Rahul Kumar Singh
Rahul Kumar Singh on 18 Nov 2020
Error using submit>parts
Too many input arguments.
Error in submit (line 3)
parts fun = parts(conf);
  1 Comment
Tom Mosher
Tom Mosher on 18 Nov 2020
I recommend you post your question on the course Discussion Forum.

Sign in to comment.


kapil vaishnav
kapil vaishnav on 16 Aug 2021
Submission failed: unexpected error: Unrecognized field name "assignmentSlug".
how to solve this?

Community Treasure Hunt

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

Start Hunting!