MATLAB Answers

3

submitWithConfiguration not working in matlab R2019b

Asked by Umang Patel on 22 Sep 2019
Latest activity Commented on by Mehrdad Abdi on 23 Sep 2019
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

So i should put it before the function's definition?
Call Addpath somewhere from your TOP function (the one that call from command windows), only once, followed by REHASH.
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.

3 Answers

Answer by Bruno Luong
on 22 Sep 2019
Edited by Bruno Luong
on 22 Sep 2019
 Accepted Answer

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

  3 Comments

Thanks for the help. That solved the problem.
You have to modify the name of 'submissionUrl' function also as the output variable of that function has the same name as of itself.
In my opinion, the best course of action would be to go back to coursera and ask them to fix their submission code. It shouldn't be down to you to fix their poorly written code.

Sign in to comment.


Answer by 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.

  0 Comments

Sign in to comment.


Answer by 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

@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.
Yes sorry i will delete that comment.
@Guillaume Oh sorry, I didn't know I can comment. I tought it's like Github issue tracking.

Sign in to comment.