Save points or data in right order

조회 수: 3 (최근 30일)
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이전 댓글 -1개 표시이전 댓글 -1개 숨기기
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 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
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 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 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];

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by