Bug in grader of MATLAB Onramp

I am learning matlab using your onramp. There is a problem with the grader on Project - Stellar Motion, task 1
The task is to make a lambda vector containing measured wavelenghts. I couldn't get the grader to accept my solution.
I didn't know if perhaps it wanted a row vector or a column vector so I tried both. I could see that the numbers looked correct but the grader rejected both my attempts. Here is the column version
lambda = [];
lambdaEnd = lambdaStart + (nObs-1)*lambdaDelta;
for n=1:nObs
lambda(n,1) =lambdaStart + (n-1)*lambdaDelta;
end
According to the Hint, it should be correct. Finally I gave up and asked for the answer.
The accepted answer is very concise, quite beyond my current knowledge:
lambdaEnd = lambdaStart + (nObs-1)*lambdaDelta
lambda = (lambdaStart:lambdaDelta:lambdaEnd)
I tried it and the grader was happy. The values are idenitcal to what I had been getting both as a row or column vector.
The problem is the grader won't accept anything besides the single solution it is expecting. This looks to me a bit too rigid.

12 Comments

Can you copy and paste the full problem statement? The question could have possibly asked for a vectorized solution.
These are short "tasks", where each task teaches some point to be learned. In general it is really great, but something went wrong on this task. Copy-paste looked terrible. I'll attach a screen capture which is much better
Just to add another detail: part of the tasks are to teach how to modify values, and how to make loops.
I looked with the Workspace at the lambda vectors (both row and column versions). The values were correct, i.e. start with lambdaStart, and on each iteration add lambdaDelta. The values were exactly what I expected and were the same values that the concise solution gave. Likewise the lenght of the vector was correct, together with the final few values which I checked.
In prinicple it should not matter how I create the vector, i.e. both solutions should give the same results (as in fact they do). Still the grader rejects my solution, which I don't understand.
"The accepted answer is very concise, quite beyond my current knowledge:"
Please revisit Ch 4.2 (Vectors and Matrices > Creating Evenly-Spaced Vectors) of MATLAB Onramp, where you were taught 2 ways to create vectors: using the colon operator, and using linspace.
Having the same issues with this. Also can't name the xlabel ("Wavelength") as an error comes up saying it is both a function and a variable, which is true, but is also what the solution states, so seems to be an incompatible answer with the grader.
@Petra what was your code? You forgot to include it. Was it like this working solution?
lambdaEnd = lambdaStart + (nObs-1)*lambdaDelta
lambda = (lambdaStart:lambdaDelta:lambdaEnd)
or did you do something else? Did you see @Cris LaPierre answer below? What was your starting value?
Can you show how the solution used used xlabel both as a solution and as a variable name? I would not think it would do that? Are you sure there is not some capitalization difference?
Project - Stellar Motion
Instructions are in the task pane to the left. Complete and submit each task one at a time.
This code loads the data and defines measurement parameters.
load starData
nObs = size(spectra,1)
lambdaStart = 630.02
lambdaDelta = 0.14
Task 1
lambdaEnd = lambdaStart + (nObs-1)*lambdaDelta
lambda = (lambdaStart:lambdaDelta:lambdaEnd)
Task 2 & 7
s = spectra(:,6)
Task 3
plot(lambda, s, ".-")
xlabel("Wavelength")
ylabel("Intensity")
Task 4
Task 5
Task 6
Further Practice
Omg, I fixed it just by adding the semicolon to the end of line 1 in task 3 facepalm
Cris LaPierre
Cris LaPierre on 9 Apr 2024
Edited: Cris LaPierre on 9 Apr 2024
That's odd. A semicolon should not have any impact on the grading here. Can you please share a full screenshot of the task with your code that causes the error and the error message displayed?
Please also mention what browser your are using and what version of the course you are taking (look in the url for "/R202__/".)
For task 3, I was having the same error: "xlabel appears to be both a function and a variable. If this is unintentional, use 'clear xlabel' to remove the variable"
I just followed the error suggestion. Here is mine:
clear xlabel
clear ylabel
plot(lambda, s, ".-")
xlabel("Wavelength")
ylabel("Intensity")
Pranit
Pranit on 9 Mar 2026
Edited: Pranit on 9 Mar 2026
I copied your same code for task 3.It still appears incorrect after submitting in my system.
There is an error preventing the assessment tests from running to completion. When working as designed, if an answer is incorrect, there is also feedback on what is incorrect. For example:
Try resetting the problem (hyperlink next to Hint | See Solution)
You could also try exiting the course and then signing back in.

Sign in to comment.

 Accepted Answer

It appears that some values are slightly different depending on how you create lambda. This has to do with floating point arithmetic. Still, for the purposes of this exercise, your values should be considered correct. I'll pass on a suggestion that a tolerance be applied when assessing the submission.
nObs = 357;
lambdaStart = 630.02;
lambdaDelta = 0.14;
lambdaEnd = lambdaStart + (nObs-1)*lambdaDelta;
for n=1:nObs
lambda1(n,1) =lambdaStart + (n-1)*lambdaDelta;
lambda2(1,n) =lambdaStart + (n-1)*lambdaDelta;
end
lambda0 = lambdaStart:lambdaDelta:lambdaEnd;
max(abs(lambda1(:)-lambda2(:)))
ans = 0
max(abs(lambda1(:)-lambda0(:)))
ans = 1.1369e-13
max(abs(lambda2(:)-lambda0(:)))
ans = 1.1369e-13

More Answers (2)

Evidently it wanted you to use the vectorized way of creating the vector :
vec = startingValue : incrementValue : finalValue
Was that the concept it had just trained you in? If so, and you didn't use that and used a for loop instead, it might think you didn't understand what it just taught you.
Petra
Petra on 9 Apr 2024
ADDITIONAL BUG FOUND IN MATLAB ONRAMP GRADER
At https://matlabacademy.mathworks.com/R2023b/portal.html?course=gettingstarted#chapter=13&lesson=2&section=1 Tasks 2-4 the final solution doesn't work even though it's the answer.
This and the above task are mitigating course completion

Tags

Community Treasure Hunt

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

Start Hunting!