1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| function exemple
figs(1) = figure('Units','Normalized',...
'Position',[0.5 0.5 0.4 0.4]);
figs(2) = figure('Units','Normalized',...
'Position',[0.5 0 0.4 0.4]);
figs(3) = figure('Units','Normalized',...
'Position',[0 0 0.4 0.4]);
figs(4) = figure('Units','Normalized',...
'Position',[0 0.5 0.4 0.4]);
axs(1) = axes('Parent',figs(1),...
'NextPLot','replaceChildren',...
'XLim',[0 10],...
'YLim',[0 10]); hps(1) = plot(axs(1),NaN,NaN);
axs(2) = axes('Parent',figs(2),...
'NextPLot','replaceChildren',...
'XLim',[0 10],...
'YLim',[0 10]); hps(2) = plot(axs(2),NaN,NaN);
axs(3) = axes('Parent',figs(3),...
'NextPLot','replaceChildren',...
'XLim',[0 10],...
'YLim',[0 10]); hps(3) = plot(axs(3),NaN,NaN);
axs(4) = axes('Parent',figs(4),...
'NextPLot','replaceChildren',...
'XLim',[0 10],...
'YLim',[0 10]);
donnees = 1:10;
dessinerEtRecupererIndice(axs(4), donnees)
indice = [];
figure(figs(4))
function dessinerEtRecupererIndice(a, mesPoles) %% <<= Rq. : j'ai mis indice en sortie
plot(a,mesPoles, 'x') %% <<= ici j'aimerai aussi spécifier que je veux dessiner dans mon axe "a"... je ne sais pas comment faire non plus - certes ça le fait comme il faut si axe est le dernier élément créé... mais c'est magique ça aussi... et si jamais j'ai créé un autre axe ou figure entre temps ? et que je veux quand même l'afficher dans l'ancien axe ?
dcm_obj = datacursormode(get(a,'Parent'));
set(dcm_obj, ...
'enable', 'on', ...
'snaptodatavertex', 'on', ...
'displaystyle', 'datatip', ...
'UpdateFcn', @myupdatefcn);
end
function [txt] = myupdatefcn(empt, event_obj)
pos = get(event_obj, 'Position');
indice = get(event_obj, 'DataIndex');
txt = {['Re: ', num2str(pos(1))], ['Im: ', num2str(pos(2))], ['Index: ', num2str(indice)]};
MajTraces
end
function MajTraces
set(hps(1),'XData',[indice indice], 'YData',ylim)
set(hps(2),'XData',xlim, 'YData',[indice indice])
set(hps(3),'XData',[0 indice], 'YData', [0 indice])
end
end |
Partager