图形对象的父级在parfor中无法读取
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
在parfor中,我无法通过 h.Parent() 的方式读取到图形对象的父对象,使用 ancestor(h, "Figure") 方法同样不行,这是为什么?
H = gobjects(3, 1);
figure("Name", "fig1", Visible="off"), H(1) = axes(); plot(1:10);
figure("Name", "fig2", Visible="off"), H(2) = axes(); plot(1:10);
figure("Name", "fig3", Visible="off"), H(3) = axes(); plot(1:10);
% for-loop
for i = 1:3
disp(class(H(i))); % matlab.graphics.axis.Axes
disp(class(H(i).Parent)); % matlab.ui.Figure
disp(class(ancestor(H(i), "figure"))); % matlab.ui.Figure
disp(H(i).Parent.Name); % Fig i
end
% parfor-loop
parfor i = 1:3
disp(class(H(i))); % matlab.graphics.axis.Axes
disp(class(H(i).Parent)); % matlab.graphics.GraphicsPlaceholder, why?
disp(class(ancestor(H(i), "figure"))); % double, why?
disp(H(i).Parent.Name); % error
end
0 Commenti
Risposta accettata
Himanshu
il 30 Mar 2023
Hello,
As per my understanding, you are facing an error while using "parfor" loop and reading the parent of a graphical object. The error occurs because accessing the properties of the parent figure or working with graphical objects directly is not supported within "parfor" loops.
When using "parfor" in MATLAB, graphical objects behave differently than in a regular "for" loop due to the nature of parallel computing. In a "parfor" loop, MATLAB creates separate worker instances that execute the loop iterations independently and in parallel. Each worker has its own workspace and does not have access to the GUI.
You can refer to the below documentation to understand more about "parfor" loops.
0 Commenti
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!