In MATLAB grader, how can I make assessments about a plot's marker shape or line width?

In MATLAB grader, how can I make assessments about a plot's marker shape or line width?
I tried the 'keyword is present' option, but it only accepts 'plot'.
I want to check whether my students succeed changing the marker shape and line width.
Is there any method to compare and assess based on what i wrote for reference solution?
It works like this. If a student wrote the exact same code with me, he/she is passed, otherwise not.
Waiting for your advice!!!!

 Accepted Answer

I dont have access to matlab grader but i think the following solution may work
add these two lines in your code template (after he plots) and lock them
M_sz = get(findobj(gca,'Type','Line'),'Marker');
L_wd = get(findobj(gca,'Type','Line'),'Linewidth');
then in assessment you can use assessVariableEqual to check Linewidth and marker

7 Comments

Thanks a lot!!
It was really helpful. Now i can evaluate their ability to change the plot characteristics.
Remember that it will work for single children, if there are more than 1 Line children in plot, output will be cell array
for Example
figure,plot(1:10,'Linewidth',5)
hold on,plot(randi([1 10],1,10),'Linewidth',3)
Now if you call
L_wd = get(findobj(gca,'Type','Line'),'Linewidth')
L_wd =
2×1 cell array
{[3]}
{[5]}
so be carefull before creating assessment
I got another question.
How can I get the variables which contain the legend or axis label info????
figure,plot(1:10,'linewidth',5,'Marker','diamond')
xlabel('X'),ylabel('Y'),title('Hello World')
legend('x')
Legend
get(gca,'Legend')
then you can access its properties
Axis label
get(gca,'Title')
get(gca,'XLabel')
get(gca,'YLabel')
One last question!!
how can i get the info about the data?
For example, students submitted plot(A,B), and I want to check if they used correct dataset or not.
Waiting for your help!
handle_line = findobj(gca,'Type','Line');
A_ploted = handle_line.XData;
B_ploted = handle_line.YData;
M_sz = handle_line.Marker;
L_wd = handle_line.LineWidth;

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!