handle h is empty while calling my function more than once

1 view (last 30 days)
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

Answers (1)

Walter Roberson
Walter Roberson on 7 Aug 2011
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.)

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!