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 CenterFile Exchange에서 Software Development Tools에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by