why there is incomplete return values from the method of a class in matlab?? help

2 Ansichten (letzte 30 Tage)
I am trying to call function B in function A in the methods of a class. then function B will call function C. C return a struct to B , then B add some fields to that struct, then return the final struct to A. But the struct can not get the values from B, the struct only has values from C. why ??? thank you so much!!!
  3 Kommentare
Derrick Gao
Derrick Gao am 14 Aug. 2018
Bearbeitet: Hans Scharler am 13 Feb. 2020
here is the three functions A B C: the return the value is a struct array. If it is a struct, it is fine I just checked.
{ function visiable_objectsIndex=Polar_Sweep_algorithm(obj,angleRange)
%1 sort angle for event queue:
%2. process the segments for status structure.
Edge22=Calculate_polar_angle(obj)%!!!!get all the info of angle coordinate.
obj.Edge2_=Edge22;
for i=1:length(Edge22) % number of end points(or event points).
Edge22(i)
Edge22(i).thetaPoint
polar_angle_endPoints(i,:)=Edge22(i).thetaPoint; %[x y height] format.
end
%pick up the objects that within the angleRange
for i=1:length(polar_angle_endPoints)
if(polar_angle_endPoints(i)>angleRange(1)||...
polar_angle_endPoints(i)<angleRange(2))
polar_angle_endPoints(i)=[];
end
end
%sort as descend order.
[angle,I]=sort(polar_angle_endPoints,'descend'); %polar angle of all the points in circle.
%using the sweep algorithm, pick up the first Event Point.
EventQueue=angle;
currentAngle=EventQueue(1);
%initial status structure.1st check the event point of
%segment. this EP should be a starting point/a intersection
%point.(3 type cases.)
Index=I(1);
pointType=Check_endPoint_type(obj,Edge2(Index));
%get the status structure at current evetn queue.
Status_structure=Generate_Status_structure(Edge2,currentAngle,pointType,Index);
w=1;
obj_count=1;
while(length(EventQueue)~=0)
w=w+1;
EventQueue=EventQueue(w:end);
currentAngle=EventQueue(1);
Index=I(w);
pointType=Check_endPoint_type(obj,Edge2(Index));
Status_structure=obj.Generate_Status_structure(Edge2,...
currentAngle,pointType,Index);
%then find the closest distance between wall and Tx. control
%the search angle!!!!
visiable_objectsIndex(obj_count)=Status_structure(1);
obj_count=obj_count+1;
end
end}
{
function Edge22=Calculate_polar_angle(obj)
%set the Tx as origional reference points.!!!if you want to set
%one specific point as reference point, let other point minus its x and y.
Tx_loc=[obj.x_,obj.y_] %reference point.
% Edge2=obj.Edge2_(visible_obj_index);% all the visible objects in the box.
Edge2=get_EdgeBundaryInsideCircle(obj);% change this !!!!!!!!!!!!
%convert the edge vertice point into polar coordinate.
size(Edge2);
for i=1:length(Edge2)
Edge=Edge2(i).point; %pick out edge point.
[theta,rho] = cart2pol(Edge(1)-Tx_loc(1),Edge(2)-Tx_loc(2));
for i=1:length(theta)
if(theta<0)
theta=abs(theta)+pi;
end
end
assert(~isempty(theta),'the theta is equal to empty ');
Edge2(i).thetaPoint=theta;
Edge2(i).rhoPoint=rho;
end
%convert the angle of end points of line segments.
for i=1:length(Edge2)
[a,b]=size(Edge2(i).segment);
bundary_segment=Edge2(i).segment;% one edge point may have 2 segments
for j=1:a
%!!!
%one end point in segment
[theta1_segment,rho1] = cart2pol(bundary_segment(j,1)-Tx_loc(1),...
bundary_segment(j,2)-Tx_loc(2));
%another end point
[theta2_segment,rho2] = cart2pol(bundary_segment(j,3)-Tx_loc(1),...
bundary_segment(j,4)-Tx_loc(2));
for i=1:length(theta1_segment)
if(theta1_segment<0)
theta1_segment=abs(theta1_segment)+pi;
end
end
for i=1:length(theta2_segment)
if(theta2_segment<0)
theta2_segment=abs(theta2_segment)+pi;
end
end
Edge2(i).theta11_segment(j)=theta1_segment;
Edge2(i).rho11(j)=rho1;
Edge2(i).theta22_segment(j)=theta2_segment;
Edge2(i).rho22(j)=rho2;
end
end
Edge22=Edge2;
end
}
{function [Edge2]=get_EdgeBundaryInsideCircle(obj)
PointsIncircle=obj.PointsIncircle_;
Edge=unique(PointsIncircle,'rows','stable');%remove the repeated points
b=1; %count the buildings
Edge1.building(b).store(1,:)=[Edge(1,1),Edge(1,2),Edge(1,3)];
Edge2(1).point=[Edge(1,1),Edge(1,2),Edge(1,3)]%store the point of edge and height.
Edge2(1).segment=[];
for i=2:length(Edge) %consider different buildings.
m=1;
if(Edge(i,4)==Edge(i-1,4)&&Edge(i,3)==Edge(i-1,3)) %same building and same height.
%store the segment in format[ x1 y1 x2 y2 height] for
%each building seperately.
bundary_segment.building(b).store(i-1,:)=[Edge(i-1,1),Edge(i-1,2),...
Edge(i,1),Edge(i,2),Edge(i,3)];%also store the height of walls.
Edge1.building(b).store(i,:)=[Edge(i,1),Edge(i,2),Edge(i,3)];
Edge2(i).bundary_segment2(m,:)=[Edge(i-1,1),Edge(i-1,2),... %store the total segment.
Edge(i,1),Edge(i,2),Edge(i,3)];
Edge2(i).point=[Edge(i,1),Edge(i,2),Edge(i,3)];
%in this way, one edge point may could be in 2 segments!!!!
Edge2(i-1).segment=[Edge2(i-1).segment;Edge2(i).bundary_segment2(m,:)];
Edge2(i).segment=[Edge2(i).segment;Edge2(i).bundary_segment2(m,:)];
elseif(Edge(i,4)==Edge(i-1,4)&&Edge(i,3)~=Edge(i-1,3))%same building ,different hight
% if(Edge(i,3)==Edge(i+1,3)) %look at it's next edge point
bundary_segment.building(b).store(i-1,:)=[Edge(i-1,1),Edge(i-1,2),...
Edge(i,1),Edge(i,2),Edge(i,3)];
Edge1.building(b).store(i,:)=[Edge(i,1),Edge(i,2),Edge(i,3)];
Edge2(i).bundary_segment2(m,:)=[Edge(i-1,1),Edge(i-1,2),... %store the total segment.
Edge(i,1),Edge(i,2),Edge(i,3)];
Edge2(i).point=[Edge(i,1),Edge(i,2),Edge(i,3)];
%one edge point may could be in 2 segments!!!!
Edge2(i-1).segment=[Edge2(i-1).segment;Edge2(i).bundary_segment2(m,:)];
Edge2(i).segment=[Edge2(i).segment;Edge2(i).bundary_segment2(m,:)];
% end
elseif(Edge(i,4)~=Edge(i-1,4)) %different building ID, start over, no relationship with before buildings.
b=b+1;% next building. new start!!
m=1;
bundary_segment.building(b).store(i,:)=[Edge(i,1),Edge(i,2),...
Edge(i+1,1),Edge(i+1,2),Edge(i,3)];%also store the height of walls.
Edge1.building(b).store(i,:)=[Edge(i,1),Edge(i,2),Edge(i,3)];
Edge2(i).bundary_segment2(m,:)=[Edge(i,1),Edge(i,2),... %store the total segment.
Edge(i+1,1),Edge(i+1,2),Edge(i,3)];
Edge2(i).point=[Edge(i,1),Edge(i,2),Edge(i,3)];%loc of edge point.
%for a new start point, it only has one segment vector!!!!
Edge2(i).segment=[Edge2(i).segment;Edge2(i).bundary_segment2(m,:)];
m=m+1;
else
i;
end
end
end
}

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by