what does thegrid{1}.points=(1:n); mean?

조회 수: 5 (최근 30일)
Ronak
Ronak 2021년 10월 13일
댓글: Dave B 2021년 10월 28일
Hello. I don't understand the underlined part. Can you please explain what is it doing?
thegrid=cell(1);
thegrid{1}.coordinate=zeros(p,1);
thegrid{1}.points=(1:n);
  댓글 수: 1
Walter Roberson
Walter Roberson 2021년 10월 28일
Could you clarify what this has to do with python (that you tagged with) ?

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

답변 (1개)

Dave B
Dave B 2021년 10월 13일
편집: Dave B 2021년 10월 13일
Cell arrays are containers for heterogenous data, each cell can hold arbitrary types/sizes/shapes. Cells are addressed with { }
The code creates a scalar cell array called grid
In the first (and only) cell in the grid, the code implicitly creates a struct. Structs are also containers that hold heterogenous data, but instead of indexing them by rows and columns it uses named fields. thegrid{1} has two fields: coordinate and points.
Inside thegrid{1}.coordinate theres a column of p zeros
Inside thegrid{1}.points are integers between 1 and n
Hope that helps, please let me know if you have more specific questions!
  댓글 수: 3
Ronak
Ronak 2021년 10월 27일
편집: Walter Roberson 2021년 10월 28일
Hi. This is a part of the code that I wrote earlier. 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;
Dave B
Dave B 2021년 10월 28일
there are a lot of little expressions in there, can you clarify which part is confusing? A good tip in MATLAB is: start with one set of values (i.e. get out of the loop by setting i and j to be 1). break the code out into its statements (i.e. take each function one at a time), run them in the command window with no semicolon so you can see what the output is.

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

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by