Asked by Umang Patel
on 22 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!

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.

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

Umang Patel
on 22 Sep 2019

Thanks for the help. That solved the problem.

Umang Patel
on 23 Sep 2019

Guillaume
on 23 Sep 2019

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.

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.

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.

Umang Patel
on 22 Sep 2019

Yes sorry i will delete that comment.

Mehrdad Abdi
on 23 Sep 2019

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 9 Comments

## Guillaume (view profile)

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/481537-submitwithconfiguration-not-working-in-matlab-r2019b#comment_748639

## Umang Patel (view profile)

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/481537-submitwithconfiguration-not-working-in-matlab-r2019b#comment_748642

## Umang Patel (view profile)

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/481537-submitwithconfiguration-not-working-in-matlab-r2019b#comment_748708

## Bruno Luong (view profile)

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/481537-submitwithconfiguration-not-working-in-matlab-r2019b#comment_748710

## Umang Patel (view profile)

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/481537-submitwithconfiguration-not-working-in-matlab-r2019b#comment_748716

## Bruno Luong (view profile)

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/481537-submitwithconfiguration-not-working-in-matlab-r2019b#comment_748722

## Umang Patel (view profile)

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/481537-submitwithconfiguration-not-working-in-matlab-r2019b#comment_748723

## Bruno Luong (view profile)

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/481537-submitwithconfiguration-not-working-in-matlab-r2019b#comment_748726

## Umang Patel (view profile)

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/481537-submitwithconfiguration-not-working-in-matlab-r2019b#comment_748727

Sign in to comment.