Frage

Ich habe überall gesucht, aber ich kann keine Site finden, die das zeigt, wie man das tut. Die Sache, die ich möchte, ist, ein Objekt von einer Achse auszuwählen, wenn ich darauf klicke, damit ich seine Farben und Sachen ändern kann.

Ich kann einfach nicht herausfinden, wie man ein Kind auswählt, ich kann Objekte erstellen, aber nicht auswählen.

Ich habe diesen Code, um eine Zeile zu erstellen: generasacodicetagpre.

Ich bin nicht sicher, ob ich die Objekte in einem Array erstellen muss, sodass ich sie bearbeiten / löschen kann. Ich glaube, ich würde Buttownfcn verwenden, aber wahrscheinlich mache ich etwas völlig falsch.

Jede Hilfe wäre dankbar, wenn ich irgendwelche Informationen vermisse, lassen Sie es mich bitte wissen

danke

War es hilfreich?

Lösung

It is not necessary to use ginput and extract the coordinates. This is done automatically by an built-in "listener" in the figure-window. You are correct in assuming that you can use the ButtonDownFcn property on the object (line, lineseries, or other handle graphics object).

Try to create at simple line from (0,0) to (1,1):

hline = line([0,1],[0,1]) %# create line, save handle in hline

Then you can set the ButtonDownFcn to, for instance, a function handle to an anonymous function:

set( ...
   hline, ...
   'ButtonDownFcn', @(handle,event)(disp(['You clicked on the line!'])) ...
);

Now try to click on the line. It should print the text in the command window.

The function needs to be able to receive atleast two arguments: (1) the handle of the object itself (the line) and (2) an "event structure". I believe the second argument is just empty when you use line-objects. But your function still needs to receive atleast these two arguments (even if you do not use them).

Read more here: http://www.mathworks.com/help/techdoc/ref/line_props.html.

You can also use your own function (a named function in a file):

set( ...
   hline, ...
   'ButtonDownFcn', @(handle,event)(namedFunction(handle,event)) ...
);

... or you can use a struct-array if you (expectedly) have other arguments beyound those two.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top