Create figure2 from point selected in figure1 until closing figure1
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I am working with a pair of figures that I would like to make more interactive. I have two vectors: v1, v2.
- In Figure 1, I plot points from v1.
- Then I select an observation in Figure 1, i_obs.
- A Figure 2 is created with a bar indicating the value v2(i_obs).
The point is that I would like to keep on clicking points in Figure 1 and creating the subsequent Figures 2 until I close Figure 1. By the moment what I have is the following, but I cannot keep Figure 1 open in order to clik and re-draw Figure 2 (it's just a single-use pair of Figures). So...any help please?
Thank you so much in advance :)
plot(v1)
datacursormode on
waitforbuttonpress
dcm_obj = datacursormode(gcf);
dc_info = getCursorInfo(dcm_obj);
figure, bar(v2(dc_info.DataIndex))
0 个评论
采纳的回答
Harsha Priya Daggubati
2020-3-20
Hi,
I guess you can use 'subplot' method available in MATLAB, if you do not want Figure 2(which is generated after a point is selected on Figure 1) to not last after next click on Figure 1 is made.
For 'subplot' doc:
subplot(2,1,1);
plot(v1);
datacursormode on;
waitforbuttonpress;
dcm_obj = datacursormode(gcf);
dc_info = getCursorInfo(dcm_obj);
subplot(2,1,2);
bar(v2(dc_info.DataIndex));
I guess inorder to make it more interactive, you can make use of click callbacks. Refer the following link:
x = 1:10;
y = [1 4 9 16 25 36 49 64 81 100];
f = subplot(2,1,1);
title('Sub Plot 1');
plot(x)
set(gcf,'WindowButtonDownFcn',@mytestcallback)
function mytestcallback(src,~)
pt = get(gca,'CurrentPoint');
subplot(2,1,2);
%Code to plot your graph
end
Hope this helps!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!