Why does findobj behave different in windows than in unix systems?

조회 수: 3 (최근 30일)
Javier Cuadros
Javier Cuadros 2024년 9월 12일
댓글: Javier Cuadros 2024년 9월 16일
Hello,
I am facing something rather curious, I am noticing a behaviour different on Matlab function findobj in Windows(10/11) or Unix ( ubuntu 22).
My issue roots to the search of figures by name, in windows I use the function like this
figHandle = findobj(groot,'Name',figName);
so providing the figName finds the figure as expected, but running same command under Matlab unix version it returns empty figHandle. I use the Matlab unix version in my CI environment where I found the issue.
Does it rely on lower OS functions that do not behave the same? Can I overcome this issue?
Thanks in advance,
Regards
  댓글 수: 2
ScottB
ScottB 2024년 9월 12일
Is HandleVisibility = "on" for the figure created on the Unix version?
Javier Cuadros
Javier Cuadros 2024년 9월 16일
Hi @ScottB I haven't modified that so if by default is on it should be. Can this cause not seeing the handle?

댓글을 달려면 로그인하십시오.

답변 (1개)

nick
nick 2024년 9월 13일
Hi Javier,
It looks like you're experiencing an issue with the "findobj" function in Ubuntu Machine. I tried to reproduce the issue; however, the function "findobj" worked as expected and returned the graphics object in both Windows and Ubuntu.
As a workaround for this potential issue, you can instead use the 'findall' function to search through all graphics objects and locate the desired one. Below is an example MATLAB script that demonstrates how to achieve this:
% Get all figure handles
allFigures = findall(groot, 'Type', 'figure');
figHandle = [];
% Iterate through each figure and check the name
for k = 1:length(allFigures)
if strcmp(allFigures(k).Name, figName)
figHandle = allFigures(k);
break;
end
end
You can refer to the following documentation to know more about the function 'findall':
  댓글 수: 1
Javier Cuadros
Javier Cuadros 2024년 9월 16일
Hi @nick thanks for the answer, I am afraid that I rather not using forloop because the each test being run spams up to 40 plots and I have 100 tests to run :S so I am afraid that iterating on all plots could be time consuming. I was looking whether findall can look for specific figure name of number to avoid the loop though

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by