Save points or data in right order

3 Ansichten (letzte 30 Tage)
sparsh garg
sparsh garg am 1 Sep. 2021
Bearbeitet: Walter Roberson am 1 Sep. 2021
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 Kommentar
sparsh garg
sparsh garg am 1 Sep. 2021
Bearbeitet: Walter Roberson am 1 Sep. 2021
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Wan Ji
Wan Ji am 1 Sep. 2021
Bearbeitet: Wan Ji am 1 Sep. 2021
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 Kommentare
sparsh garg
sparsh garg am 1 Sep. 2021
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 am 1 Sep. 2021
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];

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by