Hi all.
I am plotting sevrals of plots all in one figure. I want to use custom tool tip that shows me each plot iteration origin.
but for some reason, when using the tool tip , it shows only the last iteration number on all of the plots.
my code bellow.
what am I dong wrong?
fig=figure;hold on;for i=1:4 x=sort(rand(1,100)); y=sin(2*pi*x*i); txt = ['itr ',num2str(i)]; plot(x,y,'DisplayName',txt) dcm_obj = datacursormode(fig); set(dcm_obj,'UpdateFcn',{@myupdatefcn,'itr=',i}) endxlabel('x');ylabel('y');hold offlegend showfunction txt = myupdatefcn(~,event_obj,txt4update,Num)% Customizes text of data tips
pos = get(event_obj,'Position');I = get(event_obj, 'DataIndex');txt = {[txt4update ,': ',num2str(Num)],... ['x: ',num2str(pos(1))],... ['y: ',num2str(pos(2))]};end
Best Answer