Why does findobj behave different in windows than in unix systems?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
nick
am 13 Sep. 2024
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':
Siehe auch
Kategorien
Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!