Error trying to submit MATLAB assignment for ML Course from Stanford

8 ビュー (過去 30 日間)
Haritha GB
Haritha GB 2020 年 6 月 12 日
回答済み: Praveen Solanki 2022 年 1 月 10 日
I've noticed several problems given in the code in submitWithConfiguration.m in the lib folder for submitting the assignments online using MATLAB
For reference, let me tell you all I've tried till now:
  1. The directory is correct, all necessary files are included in the search path.
  2. I went through several posts indicating that we should rename the instance names of path and submissionUrl. This resolved the error that 'path' was not defined but hence popped up this error instead:
!! Submission failed: Not enough input arguments.
Function: parts
FileName: /MATLAB Drive/machine-learning-ex1/ex1/lib/submitWithConfiguration.m
LineNumber: 94
Please correct your code and resubmit.
This is my code (with renamed variables, and no other changes):
function submitWithConfiguration(conf)
addpath('./lib/jsonlab');
partsfun = parts(conf);
fprintf('== Submitting solutions | %s...\n', conf.itemName);
tokenFile = 'token.mat';
if exist(tokenFile, 'file')
load(tokenFile);
[email token] = promptToken(email, token, tokenFile);
else
[email token] = promptToken('', '', tokenFile);
end
if isempty(token)
fprintf('!! Submission Cancelled\n');
return
end
try
response = submitParts(conf, email, token, parts);
catch
e = lasterror();
fprintf('\n!! Submission failed: %s\n', e.message);
fprintf('\n\nFunction: %s\nFileName: %s\nLineNumber: %d\n', ...
e.stack(1,1).name, e.stack(1,1).file, e.stack(1,1).line);
fprintf('\nPlease correct your code and resubmit.\n');
return
end
if isfield(response, 'errorMessage')
fprintf('!! Submission failed: %s\n', response.errorMessage);
elseif isfield(response, 'errorCode')
fprintf('!! Submission failed: %s\n', response.message);
else
showFeedback(parts, response);
save(tokenFile, 'email', 'token');
end
end
function [email token] = promptToken(email, existingToken, tokenFile)
if (~isempty(email) && ~isempty(existingToken))
prompt = sprintf( ...
'Use token from last successful submission (%s)? (Y/n): ', ...
email);
reenter = input(prompt, 's');
if (isempty(reenter) || reenter(1) == 'Y' || reenter(1) == 'y')
token = existingToken;
return;
else
delete(tokenFile);
end
end
email = input('Login (email address): ', 's');
token = input('Token: ', 's');
end
function isValid = isValidPartOptionIndex(partOptions, i)
isValid = (~isempty(i)) && (1 <= i) && (i <= numel(partOptions));
end
function response = submitParts(conf, email, token, parts)
body = makePostBody(conf, email, token, parts);
submissionUrl_1 = submissionUrl();
responseBody = getResponse(submissionUrl_1, body);
jsonResponse = validateResponse(responseBody);
response = loadjson(jsonResponse);
end
function body = makePostBody(conf, email, token, parts)
bodyStruct.assignmentSlug = conf.assignmentSlug;
bodyStruct.submitterEmail = email;
bodyStruct.secret = token;
bodyStruct.parts = makePartsStruct(conf, parts);
opt.Compact = 1;
body = savejson('', bodyStruct, opt);
end
function partsStruct = makePartsStruct(conf, parts)
for part = parts
partId = part{:}.id;
fieldName = makeValidFieldName(partId);
outputStruct.output = conf.output(partId);
partsStruct.(fieldName) = outputStruct;
end
end
function [partsfun] = parts(conf)
partsfun = {};
for partArray = conf.partArrays
part.id = partArray{:}{1};
part.sourceFiles = partArray{:}{2};
part.name = partArray{:}{3};
partsfun{end + 1} = part;
end
end
function showFeedback(parts, response)
fprintf('== \n');
fprintf('== %43s | %9s | %-s\n', 'Part Name', 'Score', 'Feedback');
fprintf('== %43s | %9s | %-s\n', '---------', '-----', '--------');
for part = parts
score = '';
partFeedback = '';
partFeedback = response.partFeedbacks.(makeValidFieldName(part{:}.id));
partEvaluation = response.partEvaluations.(makeValidFieldName(part{:}.id));
score = sprintf('%d / %3d', partEvaluation.score, partEvaluation.maxScore);
fprintf('== %43s | %9s | %-s\n', part{:}.name, score, partFeedback);
end
evaluation = response.evaluation;
totalScore = sprintf('%d / %d', evaluation.score, evaluation.maxScore);
fprintf('== --------------------------------\n');
fprintf('== %43s | %9s | %-s\n', '', totalScore, '');
fprintf('== \n');
end
% use urlread or curl to send submit results to the grader and get a response
function response = getResponse(url, body)
% try using urlread() and a secure connection
params = {'jsonBody', body};
[response, success] = urlread(url, 'post', params);
if (success == 0)
% urlread didn't work, try curl & the peer certificate patch
if ispc
% testing note: use 'jsonBody =' for a test case
json_command = sprintf('echo jsonBody=%s | curl -k -X POST -d @- %s', body, url);
else
% it's linux/OS X, so use the other form
json_command = sprintf('echo ''jsonBody=%s'' | curl -k -X POST -d @- %s', body, url);
end
% get the response body for the peer certificate patch method
[code, response] = system(json_command);
% test the success code
if (code ~= 0)
fprintf('[error] submission with curl() was not successful\n');
end
end
end
% validate the grader's response
function response = validateResponse(resp)
% test if the response is json or an HTML page
isJson = length(resp) > 0 && resp(1) == '{';
isHtml = findstr(lower(resp), '<html');
if (isJson)
response = resp;
elseif (isHtml)
% the response is html, so it's probably an error message
printHTMLContents(resp);
error('Grader response is an HTML message');
else
error('Grader sent no response');
end
end
% parse a HTML response and print it's contents
function printHTMLContents(response)
strippedResponse = regexprep(response, '<[^>]+>', ' ');
strippedResponse = regexprep(strippedResponse, '[\t ]+', ' ');
fprintf(strippedResponse);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Service configuration
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function submissionUrl = submissionUrl()
submissionUrl = 'https://www-origin.coursera.org/api/onDemandProgrammingImmediateFormSubmissions.v1';
end
  4 件のコメント
Rahul Kumar Singh
Rahul Kumar Singh 2021 年 1 月 21 日
Error in submit (line 3)
partsfun = parts(conf);
Harsha Vardhan
Harsha Vardhan 2021 年 11 月 20 日
I am geeting same error as partsfun = parts(conf);
how to resolve it , please letme know

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2020 年 6 月 13 日
Your line
response = submitParts(conf, email, token, parts);
should be
response = submitParts(conf, email, token, partsfun);
  3 件のコメント
Harshad Koshti
Harshad Koshti 2020 年 7 月 20 日
it's not working
Cris LaPierre
Cris LaPierre 2020 年 7 月 21 日
Your first recourse should be to reach out to the course team via the discussion forum in the course. This is a custom grader they have written. Not only would they appreciate knowing of issues with it not working, but they are in the best position to help you as well.

サインインしてコメントする。

その他の回答 (3 件)

Priya Priya
Priya Priya 2021 年 9 月 18 日
Execution of script submitWithConfiguration as a function is not supported:
/MATLAB Drive/machine learning/machine learning/lib/submitWithConfiguration.m
Error in submit (line 45)
submitWithConfiguration(conf);

Priya Priya
Priya Priya 2021 年 9 月 18 日
Function: parts
FileName: /MATLAB Drive/machine learning/machine learning/lib/submitWithConfiguration.m
LineNumber: 94

Praveen Solanki
Praveen Solanki 2022 年 1 月 10 日
Function: makePostBody
FileName: /MATLAB Drive/JYmlIZ1xQWuJpSGdcTFrog_4c8166e044cf408d97b60a92beee1ff1_ex1-ex8-matlab/ex1-ex8-matlab/lib/submitWithConfiguration.m
LineNumber: 80

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by