Plotting points simultaneously with input from figure using ginput

I have six figures on which I need to plot points on the curve. I don't know how many points I need on each figure. This is my code to get all points:
for i = 1:6
figure(i)
plot(SLOPE{i, 1});
set(figure(i), 'units', 'normalized', 'outerposition', [0 0 1 1])
xlabel('Counts', 'FontSize', 12, 'FontWeight', 'bold')
ylabel(strcat('Slope\_', num2str(i)), 'FontSize', 12, 'FontWeight', 'bold')
title(strcat('SLOPE \_', num2str(i)))
hold on
[P1, P2] = ginput(10);
P1 = floor(P1);
SLOPE{i, 2} = [P1, P2];
if ~isempty(P1)
plot(P1, SLOPE{i}(P1), 'pentagram', 'Color', 'red', 'MarkerSize', 10,...
'LineWidth', 2, 'MarkerFaceColor', 'black');
end
end
I don't need more than 10 points in each figure, for some figures, I don't need any points. My problem is that I want each point to be plotted after I select it. With the above code, I can see all points plotted in a figure on hitting enter after I select all points. I have tried using 'waitforbuttonpress' along with a while loop, but a click is also considered a button press. Any help would be greatly appreciated.
Thanks,
Koustubh

Antworten (1)

You need to have an inner loop over the number of points
for i = 1:6
for n = 1 : 10
[x,y] = ginput(1); % Get one point at a time.
plot(..........
end
end

4 Kommentare

If I make an inner loop like this:
for i = 1:6
for n = 1:10
figure(i)
plot(SLOPE{i, 1});
set(figure(i), 'units', 'normalized', 'outerposition', [0 0 1 1])
xlabel('Counts', 'FontSize', 12, 'FontWeight', 'bold')
ylabel(strcat('Slope\_', num2str(i)), 'FontSize', 12, 'FontWeight', 'bold')
title(strcat('SLOPE \_', num2str(i)))
hold on
[P1, P2] = ginput(1);
P1 = floor(P1);
SLOPE{i, 2} = [P1, P2];
if ~isempty(P1)
plot(P1, SLOPE{i}(P1), 'pentagram', 'Color', 'red', 'MarkerSize', 10,...
'LineWidth', 2, 'MarkerFaceColor', 'black');
end
end
end
I have to select 10 points before I can go on to the next figure. I don't know the number of points I need in a figure. I tried using a while loop before with 'waitforbuttonpress', but, it doesn't work because a mouse click and hitting enter are both considered button presses.
No. The figure() and some other lines should not be inside the inner loop of course. Try again.
Do you want all 10 graphs up before any clicking starts? And the user can go into any one of the 10 plots that they want and click there? If so, that's entirely different and more complicated code.
I figured it out. I needed to save those points too. For each figure, points are stored in the second column of 'SLOPE'. First column has plotting data for each figure. Much more looping needed than I anticipated.
SLOPE = cell(6, 2);
for i = 1:6
figure(i)
plot(SLOPE{i, 1});
set(figure(i), 'units', 'normalized', 'outerposition', [0 0 1 1])
xlabel('Counts', 'FontSize', 12, 'FontWeight', 'bold')
ylabel(strcat('Slope\_', num2str(i)), 'FontSize', 12, 'FontWeight', 'bold')
title(strcat('SLOPE INJ\_', num2str(i)))
hold on
TEMP = zeros(100, 1);
for N = 1:100
[P1, ~] = ginput(1);
if ~isempty(P1)
P1 = floor(P1);
else
P1 = 0;
end
TEMP(N) = P1;
Key = get(figure(i), 'CurrentCharacter');
if ~isempty(Key)
break
end
if ~isempty(P1)
plot(P1, SLOPE{i}(P1), 'pentagram', 'Color', 'red', 'MarkerSize', 10,...
'LineWidth', 2, 'MarkerFaceColor', 'black');
end
end
if length(TEMP) == 1
SLOPE{i, 2} = [];
else
TEMP = sort(TEMP(1:N - 1), 'ascend');
SLOPE{i, 2} = [TEMP, SLOPE{i, 1}(TEMP)];
end
end
Thank you for your help!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Exploration finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 23 Jul. 2016

Kommentiert:

am 24 Jul. 2016

Community Treasure Hunt

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

Start Hunting!

Translated by