Getting the X and Y coordinates of the points from the figure

7 ビュー (過去 30 日間)
kaivlya patel
kaivlya patel 2020 年 5 月 20 日
コメント済み: Image Analyst 2020 年 5 月 21 日
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:
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.

回答 (1 件)

Image Analyst
Image Analyst 2020 年 5 月 20 日
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 件のコメント
kaivlya patel
kaivlya patel 2020 年 5 月 20 日
one last thing I would like to know, how can I export this x and y coordintes value to the excel file using writematrx command?
Image Analyst
Image Analyst 2020 年 5 月 21 日
xy = [pareto_frontier(:, 2), pareto_frontier(:, 3)];
writematrix(xy,'pareto_frontier.xlsx');

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDescriptive Statistics and Visualization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by