Hi HAINGKHARRAN ,
To accomplish your requirement of plotting multiple concentric circles at different locations and editing the labels manually , I made a few modifications to your code:
- Hold on is used instead of hold all as it is deprecated.
- The user is now provided with graphical dialog box instead using the command line for confirmation.
- Ability to manually edit the label of the circles is added. To achieve the functionality of editing the label of each circle manually, you can use a callback function which will helps to edit the text by allowing user to input the label in a dialog box.
You can refer to the following code snippet-:
I = imread('aaaa.png');
figure(1)
imshow(I)
th = linspace(0, 2*pi);
hold on
while true
message = sprintf('Click where you want the center to be');
uiwait(helpdlg(message));
[xCenter, yCenter] = ginput(1);
% Check if the user pressed "Enter" without clicking
if isempty(xCenter)
break;
end
X = [5, 30, 100]; % Radius of the concentric circles defined
for radius = X
x = radius * cos(th) + xCenter;
y = radius * sin(th) + yCenter;
h = plot(x, y, '-');
title('Risk Contour')
% Label the circle with its radius and make the label editable
labelStr = sprintf('%.2f', radius);
textHandle = text(xCenter, yCenter - radius, labelStr, ...
'Color', h.Color, ...
'VerticalAlignment', 'bottom', ...
'HorizontalAlignment', 'center', ...
'BackgroundColor', 'w', ...
'Margin', 1, ...
'FontWeight', 'bold', ...
'ButtonDownFcn', @editText); % Add callback for editing
end
% Ask the user if they want to continue or stop
choice = questdlg('Do you want to plot another contour?', ...
'Continue', 'Yes', 'No', 'Yes');
if strcmp(choice, 'No')
break;
end
end
% Callback function for editing text labels
function editText(src, ~)
% Prompt user for new label
newLabel = inputdlg('Enter new label:', 'Edit Label', 1, {src.String});
if ~isempty(newLabel)
src.String = newLabel{1}; % Update the label
end
end
You might also find these references useful:
- https://www.mathworks.com/help/matlab/ref/questdlg.html
- https://www.mathworks.com/help/matlab/creating_plots/create-callbacks-for-graphics-objects.html
Hope this helps.