Partitioning and removing an array of data
2 次查看(过去 30 天)
显示 更早的评论
Hi. Can you please explain what is it doing here (Bold lines)? As far as I know it must remove gridpoints from thegrid and partitions gridpoints with a probability (prob). But I don't understand how it is doing the removing and patirioning.
for j=1:L
gridpoints=[gridpoints,thegrid{j}.coordinate];
npoints=length(thegrid{j}.points);
directions_numeric=sign(X_data(:,thegrid{j}.points)-thegrid{j}.coordinate*ones(1,npoints));
directions=num2cell(num2str(directions_numeric'),2);
numericmap=containers.Map(directions,num2cell(directions_numeric,1));
cubemap=containers.Map(directions,cell(npoints,1));
for i=1:npoints
cubemap(directions{i})=[cubemap(directions{i}),i];
end;
keyset=keys(cubemap);
valset=values(cubemap);
for i=1:length(cubemap)
activesize=length(valset{i});
if(activesize>gamma)
prob=1-0.5*exp(-epss*(activesize-gamma));
else
prob=0.5*exp(epss*(activesize-gamma));
end;
if(random('bino',1,prob)>0.5)
tempobj.coordinate=thegrid{j}.coordinate+side_length/2*numericmap(keyset{i});
tempobj.points=valset{i};
newgrid=[newgrid,tempobj];
end;
end;
0 个评论
回答(1 个)
Ishu
2024-3-27
Hi Ronak,
Here you are dealing with a struct "thegrid{1}" which has two fields "coordinate" and "points". In the loop you are iterating over a list of grid cells "thegrid' of lenght "L".
For each cell it extracts the cell's central coordinate and the indices of data points associated with this cell. Then it calculates the direction of each point relative to the cell's center, storing it in a matrix "directions_numeric" where each column represents the direction of a point relative to the center.
Next, the code converts the numeric directions to strings "directions" and then to cell arrays, which are used as keys in two maps "numericmap" and "cubemap". The "numericmap" associates each direction with its numeric representation. The "cubemap" is intended to group points by their direction relative to the cell's center.
In last, it iterates over all points, appending the index of each point to the appropriate entry in "cubemap" based on its direction.
For more information on how the data is stores in "structs" you can refer below documentation:
Hope it helps.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!