Produce plot by clicking point in a current plot
Show older comments
Hi there,
I am currently trying to write a code which runs a function through two loops for example:
x = [1:10];
y_mtx=zeros(10);
for ii = 1:10
for jj = 1:10
y_mtx(ii,jj)=x(ii)*jj;
end
end
figure(1)
plot(x,y_mtx,'b*-')
hold on, grid on
This produces a plot with 10 lines, each connected by 10 points. And for each point there is a unique ii,jj value which has been used in the calculation. So for example if you were to click on the first point on the third line up, ii = 3, jj = 1. My desire is that when the user clicks a particular point in this plot, it uses these ii and jj values to plot the following:
% these values taken as example of the first point on the third line being clicked
ii = 3;
jj = 1;
x_2 = linspace(0.5*x(ii),1.5*x(ii),10);
y_2 = linspace(0.5*y_mtx(jj),1.5*y_mtx(jj),10);
z = x_2'*y_2.^2;
figure(2)
plot(x_2,z,'r-')
hold on, grid on
Ideally, I would essentially like to store the plot within the point and only reveal it when the point is clicked, but I don't know whether that is possible. Does anyone have any ideas?
Many thanks,
Nick
Answers (0)
Categories
Find more on Annotations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!