Вопрос

Я искал везде, но я не могу найти сайт, который показывает, как это сделать. То, что хочу, чтобы иметь возможность выбрать объект с осей, когда я нажимаю на него, чтобы я мог изменить его цвета и материал.

Я просто не могу понять, как выбрать ребенка, я могу создавать объекты, но не выбрать их.

У меня есть этот кусок кода, который я использую для создания строки:

coord = ginput (2)
x = coord(:,1)
y = coord(:,2)
hline = line(x,y)
.

Я не уверен, что мне нужно создать объекты в массиве, чтобы я мог выбрать «Изменить / удалять». Я считаю, что мне нужно будет использовать buttonondownfcn, но, вероятно, я делаю что-то совершенно не так.

Любая помощь будет оценена, если мне не хватает какой-либо информации, пожалуйста, дайте мне знать

Спасибо

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top