How to check plot-properties for multiple lines in one plot - Grader
Mostrar comentarios más antiguos
Hello everyone,
iam trying to write a grader-assessment that's comparing plot-properties.
The students have to use given colors for 3 different plots in the same plot. But currently iam struggeling to check those properties..
I had the idea to save the information of the gca in a variable in the students template.
hold on
plot(diode3d(:,1,1),diode3d(:,2,1),'r');
plot(diode3d(:,1,2),diode3d(:,2,2),'b');
plot(diode3d(:,1,3),diode3d(:,2,3),'g');
hold off
ax = get(gca);
The line-options are being saved in 'Children' as line-array, so i though it should be possible to compare the line-color for all 3 lines with a for-loop. And in case the color doesn't fit for any of the line-childrens, an error with feedback appears. Even one wrong color would be enough to give the same feedback - doesn't matter which one is wrong
% Get reference solution for ax.
axReference = referenceVariables.ax;
for i=1:3
assert(ax.Children(i).Color == axReference.Children(i).Color);
end
But iam only getting the error-message "Invalid or deleted object."... Does anyone have an idea, what iam missing?
Thanks you very much in advance! :)
1 comentario
Mitch Lautigar
el 21 de Abr. de 2022
When comparing plot properties, there are several things to keep in mind. Predominantly, the figure has to be open so it can be treated as a valid object. Once it's open, it's simply a matter of setting the figure title to a variable to check the properties. See answers below for if creating a figure, or opening a figure. I've also posted a link on accessing figure properties and what they are down at the bottom of my post.
If opening a figure (assuming this is done from a file that was was saved to the workspace):
f = figure(n); where n is whatever the figure number is. If the figure has a title, n would need to equal the title.
If creating a figure,
f = figure; %still creates a new figure, but leaves the properties in f where they can be edited and controlled.
Hope this helps!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Annotations en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
