필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

when we run the code, a plot comes out and if i want to calculate the X and y coordinate of center of each grid box , how to do that ?

조회 수: 1 (최근 30일)
xyRange=[1,5]; %// Starting xy range of particles
P=3; %// Number of particles generated each day
vx=0.6; vy=0.4;%// x and y velocity
al=35;at=5;t=1;
X=[]; Y=[]; %// Vectors start out empty
for day=1:5
%// Generate 3 particles and add to end of vectors X and Y
X=[X;randi(xyRange,P,1)];
Y=[Y;randi(xyRange,P,1)];
%// Move all the particles
X=X+vx+randi([-6,6],1,1)*sqrt(2*al*vx*t)+randi([-6,6],1,1)*sqrt(2*at*vy*t);
Y=Y+vy+randi([-6,6],1,1)*sqrt(2*al*vy*t)+randi([-6,6],1,1)*sqrt(2*at*vx*t);
end
plot(X,Y,'kd');grid on;
xGridMarkers = str2double(get(gca,'XTicklabel'));
yGridMarkers = str2double(get(gca,'YTickLabel'));
numXSquares = length(xGridMarkers) - 1;
numYSquares = length(yGridMarkers) - 1;
squareHitCount = zeros(numYSquares, numXSquares);
for k=1:size(X,1)
x = X(k);
y = Y(k);
ySqrIdx = numYSquares - (find(yGridMarkers>y,1) - 1) + 1;
xSqrIdx = find(xGridMarkers>x,1) - 1;
squareHitCount(ySqrIdx, xSqrIdx) = squareHitCount(ySqrIdx, xSqrIdx) + 1;
end
  댓글 수: 1
RahulTandon
RahulTandon 2015년 7월 8일
use the ginput function read about it in the help roughly 1) get the plot in place 2) call ginput 3) click on every point that you are interested in 4) finish by pressing enter 5) you will get an array of points in your workspace and in the command window TRY IT!

답변 (0개)

이 질문은 마감되었습니다.

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by