MATLAB Answers

submitWithConfiguration not working in matlab R2019b

853 views (last 30 days)
Umang Patel
Umang Patel on 22 Sep 2019
Commented: Tom Mosher on 31 Aug 2020 at 3:04
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!

  9 Comments

Show 6 older comments
Umang Patel
Umang Patel on 22 Sep 2019
So i should put it before the function's definition?
Bruno Luong
Bruno Luong on 22 Sep 2019
Call Addpath somewhere from your TOP function (the one that call from command windows), only once, followed by REHASH.
Umang Patel
Umang Patel on 22 Sep 2019
Ohh I see what you are saying. It will process the addpath command everytime whereas it is not necessary to do so everytime and doing it only will suffice.

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

  13 Comments

Walter Roberson
Walter Roberson on 20 Jul 2020
"It's not working" might be an acceptable description of a problem when you tow your car to a mechanic, because the mechanic would have the car right there to be able to test and plug diagnostic monitors into. It is, however, not an acceptable description of a problem with a computer program, as we cannot see your screen from here and we do not have an account on that system to test with.
Tom Mosher
Tom Mosher on 31 Aug 2020 at 0:58
Between "it doesn't work" and "I have exactly the same problem", that covers about 50% of the posts on the Machine Learning course forum.

Sign in to comment.

More Answers (7)

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.

  4 Comments

Show 1 older comment
dhana lakshmi
dhana lakshmi on 29 May 2020
how did this submitwithconfiguration code problem got resolved

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.

  6 Comments

Show 3 older comments
Parth Rastogi
Parth Rastogi on 11 Apr 2020
Sir I am still facing the same problem and my deadlines are coming closer
Robin Mailhot
Robin Mailhot on 13 Apr 2020
Thank you Tom ! To everyone saying it doesnt work, you need to go to week 2, environnement setup instruction, reading, acces matlab online tutorial..., downloaded the updated exercices. The follow the instructions. Worked for me and I hope it will for you !
Sarwan Kumar
Sarwan Kumar on 11 Jul 2020
Hello Tom and other fellows,
I downloaded the updated zip file from the "Week 2 - Environment Setup Instructions - Reading: Access the MATLAB Online Trial and Exercise Files for MATLAB users" but still facing the same error. To assure you that I have downloaded the zip files from right page, I have pasted the link that page below.
Below mentioned is the error that I am receiving again and again.
>>submit
Warning: Function Warning: Name is nonexistent or not a directory: /MATLAB Drive/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/./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:
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);
Please help!

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.

  3 Comments

Kazem Edmond
Kazem Edmond on 30 Aug 2020 at 23:42
If you're trying to update your existing scripts, then be sure to replace both submit.m and also the "lib" directory, which contains files used by submit.m. Replacing submit.m alone will not improve anything.
Tom Mosher
Tom Mosher on 31 Aug 2020 at 0:56
I recommend you use the correct scripts in the first place.
  • Tom, ML course mentor

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.

  3 Comments

Guillaume
Guillaume on 22 Sep 2019
@Mehrdad Abdi, how is that an answer to the question? Please use comment on this question instead of clicking answer this question unless you are actually providing a solution.
@Umang Patel, as I wrote in my first comment to you, the parts function that comes with matlab (in the toolboxes) is not the parts function you are using. Matlab's parts function does not accept a structure as input. You are passing a structure to parts.
Mehrdad Abdi
Mehrdad Abdi on 23 Sep 2019
@Guillaume Oh sorry, I didn't know I can comment. I tought it's like Github issue tracking.

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);

  2 Comments

Tom Mosher
Tom Mosher on 4 Jun 2020
Questions about the Coursera "Machine Learning" course should be posted on course Discussion Forum.
Yasir Khan
Yasir Khan on 6 Jun 2020
if in the following Assignment one programmme is not running then the rest of the programme can be submit with out any error?

Sign in to comment.


Tom Mosher
Tom Mosher on 31 Aug 2020 at 0:59
I request that the OP of this thread please close it to further comments.
The question has been answered multiple times.

  2 Comments

Walter Roberson
Walter Roberson on 31 Aug 2020 at 2:48
There is no current ability to close a Question to further responses, except by closing the entire Question. However people are still encountering the problem, so it should not be closed.
Tom Mosher
Tom Mosher on 31 Aug 2020 at 3:04
If the question is closed, would it still be available to read? Since the answers have already been provided, that would be sufficient.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!