How to check plot-properties for multiple lines in one plot - Grader
古いコメントを表示
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 件のコメント
Mitch Lautigar
2022 年 4 月 21 日
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!
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Annotations についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
