handle h is empty while calling my function more than once

1 次查看(过去 30 天)
hi,
In my plotting function shown below, handle h is empty (even though i can see in my workspace its value) when the function is called more than once. This happens only if i call this function more than once. For the first time it plots my curve just fine.
Is there something wrong with my code? Can I use something other that findobj? Please advise
function logPlot(i, idx, color, hObject, eventdata, handles)
global wlog
X = wlog.sel_curves(:,idx);
Y = wlog.sel_curves(:,1);
h = findobj(gcf,'tag',strcat('Log',num2str(i)));
plot( X, Y, 'Parent', h, 'color', color);
if i == 1
set(h, 'YDir', 'reverse','XYTickLabel', sprintf('%5.2f', wlog.sel_curves(:,1)));
Ylabel(h, strcat(wlog.sel_curve_info(1,1), ' (',wlog.sel_curve_info(1,2),')'));
else
set(h, 'YDir', 'reverse', 'XTickLabel', [], 'YTickLabel', []);
end

回答(1 个)

Walter Roberson
Walter Roberson 2011-8-7
We do not know if "hold" is on for the axes or not. If it is not then the before before adding any high-level graphic object is to clear out the existing graphics objects in the axes, which could potentially remove the object with the desired tag (if it is in the same axes.)

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by