Getting the X and Y coordinates of the points from the figure
14 views (last 30 days)
Show older comments
Hi all,
I am running a code and at the end, the figure is generating with the points. The detail description and the figure is attached below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/295273/image.jpeg)
Here, I want to calculate the distace of all the red dots from the green Utopia star. And for that, I want to get the the X and Y coordinates of all the red dots. I am also attaching the code for this figure here:
%Plotting the tradespace and pareto frontier with corresponding architectures
Utopia = UtilityHighRange; % for plotting purposes add Utopia point
plot(archs_cost(1),archs_util(1),'b.','Tag',sprintf('ix %d\n%s',1, join(archs(1,:))) )
hold on % moved up from below
for n = 2:n_arch
plot(archs_cost(n),archs_util(n),'b.','Tag',sprintf('ix %d\n%s',1, join(archs(n,:))) )
end
datacursormode on
dcm = datacursormode(gcf);
set(dcm,'UpdateFcn',@myupdatefcn)
xlabel('Cost')
ylabel('Utility')
xlim([CostLowerRange CostHighRange])
ylim([UtilityLowerRange UtilityHighRange])
title('Trade Space Pareto')
hold on
plot(Utopia,'pg','LineWidth',5)
annotation('textarrow',[0.1657 0.1357],[0.8738 0.9238],'String','Utopia')
plot(pareto_frontier(1, 2), pareto_frontier(1, 3), 'rs', 'LineWidth', 3, 'Tag', sprintf('ix %d\n%s', 1, join(pareto_frontier_archs(1, :))))
hold on
for n = 2:frontier_idx
plot(pareto_frontier(n:frontier_idx, 2), pareto_frontier(n:frontier_idx,3), 'rs', 'LineWidth', 3, 'Tag', sprintf('ix %d\n%s', 1, join(pareto_frontier_archs(n, :))))
end
datacursormode on
dcm = datacursormode(gcf);
set(dcm, 'UpdateFcn', @myupdatefcn)
hold off
In here, the red dots shows the pareto_frontier points into the figure. The coordinates are getting generated into the figure for all the red dots, however I would like to print all the coordinates in the command window. I have also used the handle, get(pareto_frontier, 'XData'), but it is not generating the result.
Any help in this perticular will be highly appreciated and I would be really greatful for it as I am in a urgent need of this solution.
Thank you.
0 Comments
Answers (1)
Image Analyst
on 20 May 2020
Why can't you just use fprintf():
for k = 1 : length(pareto_frontier(:, 2))
fprintf('x = %f, y = %f.\n', pareto_frontier(k, 2), pareto_frontier(k, 3));
end
3 Comments
Image Analyst
on 21 May 2020
xy = [pareto_frontier(:, 2), pareto_frontier(:, 3)];
writematrix(xy,'pareto_frontier.xlsx');
See Also
Categories
Find more on Calendar in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!