How to define, edit and delete ROI in a (scatter) plot?

3 ビュー (過去 30 日間)
Csaba 2016 年 4 月 6 日
コメント済み: Csaba 2016 年 4 月 14 日
I have a plot of data of some measurement. I want to define several ROIs in the plot, in order to make fitting, or determine the baseline or whatever reason, and I need these ROIs in a variable (or variables). Is it possible to make it grafically? All the methods I tried (imline, brush, datacursor) are for different task and does not allow editing, deleting the ROIs both from the picture and from the variable, I was not able to follow the changes I have made when tried i.e. change the limits of the ROI.
I think there should be something but I could not find it. It is so essential when someone wants to evaluate the data.
Thanks for any suggestions.

回答 (2 件)

Debarati Banerjee
Debarati Banerjee 2016 年 4 月 12 日
For the function 'imline', you can use the method 'delete' to delete the the ROI object from figure. You may edit the position of the ROI using the method 'setPosition'.
Please refer to the section 'Methods' of the following link for more details:
For your case, you may find the function ' imfreehand ' helpful as well.
Hope this helps!
Cheers, Debarati
  1 件のコメント
Csaba 2016 年 4 月 12 日
Thank you for your answer.
I tried imline and it does not work properly at least for me. There are several problems.
Just one of them: If someone deletes the line by mouse right click there is no way (or at least I did not found) to follow which "imline" was deleted. There is no "addDeleteCallback" function, and how to determine which handle was deleted, and was it really deleted?
Second: If someone modifies the position of the whole or just one of the endpoints by mouse, there is no way to identify (or at least I did not found) which imline was modified. There is an "addNewPositionCallback" function but the function it calls does not have the handle to the imline in question. The Help says:
"Whenever the ROI object changes its position, each function in the list is called with the syntax:
where pos is of the form returned by the object's getPosition method."
So no handle information is given to the function. I have several ROIs on the same plot, so it would be essential to know which ROI was modified.
I have found several other drawbacks using imline so I gave up. If you can solve these problems please tell me how. I am not a really educated Matlab user.


Debarati Banerjee
Debarati Banerjee 2016 年 4 月 13 日
You may use the 'DeleteFcn' property to call a function when an 'imfill' object is being deleted.
>> set(h,'DeleteFcn',{@fcn}) % where h is an imfill object
In the 'fcn' function you can pass aapropriate display commands which will display messages in Command Window and help you in understanding which object is deleted/ position is changed.
  3 件のコメント
Csaba 2016 年 4 月 14 日
Thank for your answers, they really help me a lot! I also made my homework and found that with set it is possible to do a lot of things I did not even know before.
I am almost done, however your test.m does not give me what I need.
I tried to modify it a bit and found that the third parameter of the test.m which was ~-ed in your file contains the real handle to the imline. So getPosition(parameter3) gives me back the positions of the imline to be deleted. So far so good.
I have several question though, the answer of which I could not find in the help. Please help me in this.
Can you tell me what are the other two (or maybe more???) parameters in test.m and what can I do with them? The first parameter is a 1x1 Group (I do not know what does this mean), the second parameter says that it is a 1x1 EventData, It says that event is a deletion and also contains a 1x1 Group.
I suppose that a similar method can be used for the new position of the imline. It is important for me because I want to handle the case when the endpoints are changed also. Can you also help me in that?
Thank you for your kindness, I really appreciate it!



Help Center および File ExchangeTitle についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by