Save points or data in right order

4 ビュー (過去 30 日間)
sparsh garg
sparsh garg 2021 年 9 月 1 日
編集済み: Walter Roberson 2021 年 9 月 1 日
For the below image,the initial plot is as follows
After doing set(gca,'YDir','reverse'); I am able to correct the display to get this
Now what I would like to know is there a way to store the points after reversing the Y Direction
  1 件のコメント
sparsh garg
sparsh garg 2021 年 9 月 1 日
編集済み: Walter Roberson 2021 年 9 月 1 日
so I read that we can obtain x and y using h.xData and h.yData
So ,this is what I did
plot(pts(1,:),pts(2,:));
set(gca,'YDir','reverse');
ax=gca;
h = findobj(gca,'Type','line');
x = h.XData;
y = h.YData;
Final_set_pts=[x;y];
however when I plot final_set_pts,the result is same as before,any suggestions on what i am doing wrong here will be welcome.

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

採用された回答

Wan Ji
Wan Ji 2021 年 9 月 1 日
編集済み: Wan Ji 2021 年 9 月 1 日
I have answered this question before, now I have a better solution to this problem which can identify many connected regions
clc;clear
load('pts.mat');
pointSet = X_pts;
figure(1)
clf; hold on
scatter(pointSet(:,1),pointSet(:,2),40,'filled','k')
n=1;
while ~isempty(pointSet)
circleSetInd=1;
for j=1:length(pointSet)
disSet=sqrt(sum((pointSet-pointSet(circleSetInd(end),:)).^2,2));
[~,ind]=sort(disSet);
ind=ind(1:5);
[~,~,t_ind]=intersect(circleSetInd,ind);
ind(t_ind)=[];
if ~isempty(ind)
circleSetInd=[circleSetInd;ind(1)];
else
n=n+1;
circleSet{n}=pointSet(circleSetInd,:);
pointSet(circleSetInd,:)=[];
break
end
end
end
q = cellfun(@isempty,circleSet);
circleSet = circleSet(~q);
for i=1:numel(circleSet)
plot(circleSet{i}(:,1),circleSet{i}(:,2),'LineWidth',2)
hold on
end
set(gca,'YDir','reverse');
Or you can set some more connected regions
clc;clear
t = linspace(0,2*pi,101)';
x = 10*cos(t);
y = 10*sin(t).*cos(2*t);
pointSet = [x, y]; % this point set is generated for test
figure(1)
clf; hold on
scatter(pointSet(:,1),pointSet(:,2),40,'filled','k')
n=1;
while ~isempty(pointSet)
circleSetInd=1;
for j=1:length(pointSet)
disSet=sqrt(sum((pointSet-pointSet(circleSetInd(end),:)).^2,2));
[~,ind]=sort(disSet);
ind=ind(1:5);
[~,~,t_ind]=intersect(circleSetInd,ind);
ind(t_ind)=[];
if ~isempty(ind)
circleSetInd=[circleSetInd;ind(1)];
else
n=n+1;
circleSet{n}=pointSet(circleSetInd,:);
pointSet(circleSetInd,:)=[];
break
end
end
end
q = cellfun(@isempty,circleSet);
circleSet = circleSet(~q);
for i=1:numel(circleSet)
plot(circleSet{i}(:,1),circleSet{i}(:,2),'LineWidth',2)
hold on
end
set(gca,'YDir','reverse');
  2 件のコメント
sparsh garg
sparsh garg 2021 年 9 月 1 日
thanks for the discussion.
Two things ,
the new code is still not generalizing and fails on the foll test case
Moreover,for the current question what I want is that when we do set(gca,'YDir','reverse),the resultant points that show up on the figure,that is the correct order I want.
So in order to do that what can I do,I have tried rotating the original set of reordered points(from your code) by a rotation matrix but that doesn't work,
Wan Ji
Wan Ji 2021 年 9 月 1 日
Well, this is not a problem, you just need a photo size to do this then
plot(pts(1,:),max(pts(2,:))+1-pts(2,:));
% set(gca,'YDir','reverse');
ax=gca;
h = findobj(gca,'Type','line');
x = h.XData;
y = h.YData;
Final_set_pts=[x;y];

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpectral Measurements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by