Effacer les filtres
Effacer les filtres

Error using str2num (line 32), Requires string or character array input. Error in xGridMarkers = str2num(ge​t(gca,'XTi​cklabel'))​; how to remove this error??

34 vues (au cours des 30 derniers jours)
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 = str2num(get(gca,'X'));
yGridMarkers = str2num(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
  2 commentaires
Guillaume
Guillaume le 8 Juil 2015
If you're asking help about an error, post the entire error message as it appears on screen, particularly the part that states where the error occurs.

Connectez-vous pour commenter.

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 8 Juil 2015
Modifié(e) : Azzi Abdelmalek le 8 Juil 2015
Use str2double, because get(gca,'XTicklabel') is a cell array
xGridMarkers = str2double(get(gca,'XTicklabel'));
yGridMarkers = str2double(get(gca,'YTickLabel'));
  1 commentaire
sneha kriplani
sneha kriplani le 9 Juil 2015
@azzi if i need to find out x and y coordinate of center of each grid box then how to do ?? please help.Thnaks in advance

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur NaNs dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by