I am trying to create a normal random moving point for each individual point in a 3D scatter point. How do I go about to do this?

5 Ansichten (letzte 30 Tage)
I am trying to replicate the random movements (gaussian distribution) found in particles and to do that, I have already made a moving plot (in a normal random distribution) but I am trying to have a maybe 5 by 5 number of points with each point having its on random moving point.
Code attached are the moving plot and the scatter plot
  2 Kommentare
darova
darova am 7 Apr. 2020
Can you be more specific? Here is the result of one of your script
How do you want it to look like?
sui zhi lau
sui zhi lau am 7 Apr. 2020
Hi Darova,
Thanks for replying! For the moving plot, this would be counted as the movement for one 'particle'. So would it be possible for multiple points to be moving cocurrently in the same plot.
So for the no magnetic field code, I would like to have each point's arrow moving randomly. so it would be:
But with the same moving plot for each points on this plot.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

darova
darova am 7 Apr. 2020
What about this?
n = 5;
[X,Y] = meshgrid(1:n); % create mesh
T = 180*rand(n)-90; % initial angles
cla
plot(X(:),Y(:),'ob') % plot starting points
hold on
for i = 1:30
T = T + rand(n)*90 - 45; % increase/decrease angle
X = X + 0.05*cosd(T); % increase/decrease X coordinate
Y = Y + 0.05*sind(T); % increase/decrease Y coordinate
plot(X(:),Y(:),'.r') % plot new coordinates
pause(0.1)
end
hold off
  24 Kommentare
sui zhi lau
sui zhi lau am 28 Apr. 2020
I tried it and it showed this
I dont see the random movements or the coverging to the centre.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
niter = 40; % no. of jumps
scale = 0.5;
y = 1; % white percentage
%% range of results
d = 1;
nmesh = 4; %range
[X,Y,Z] = meshgrid((-nmesh+1):nmesh-1); % create mesh
X = X * d;
Y = Y * d;
Z = Z * d;
%% random direction for X,Y,Z
dx = normrnd(0,1,[(size(X,1))^3 niter]);
dy = normrnd(0,1,[(size(X,1))^3 niter]);
dz = normrnd(0,1,[(size(X,1))^3 niter]);
%% Magnetised particles
c0 = nmesh; % center of magnetic field
for i = 1:size(dx,1)
[ii,jj,kk] = ind2sub(size(X),i); % row and column of force
n = pdist2([ii jj kk],[c0 c0 c0]); % distance to point
if n < 2.1 % radius of magnetic force
dx(i,:) = -cumsum(dx(i,:)*0+(ii-c0)/n); % cosinus
dy(i,:) = -cumsum(dy(i,:)*0+(jj-c0)/n); % sinus
dz(i,:) = -cumsum(dz(i,:)*0+(kk-c0)/n);
end
end
cla
%plot3(X(:),Y(:),Z(:),'ob') % plot starting points
hold on
%plot(X,Y,'k') % plot grid
%plot(X',Y','k')
%% For Loop to plot graph
for i = 1:niter-1
X1 = X(:) + dx(:,i);
Y1 = Y(:) + dy(:,i);
Z1 = Z(:) + dz(:,i);
%q = quiver3(X1, Y1, Z1, dx(:,i+1)-dx(:,i), dy(:,i+1)-dy(:,i),dz(:,i+1)-dz(:,i))
%q.LineWidth = s;
%q.ShowArrowHead = 'off';
plot3([X(:) X(:)]'+[dx(:,i+1) dx(:,i)]', ...
[Y(:) Y(:)]'+[dy(:,i+1) dy(:,i)]',...
[Z(:) Z(:)]'+[dz(:,i+1) dz(:,i)]','.-r')
pause(0.001)
%% percentage readings
Image = getframe();
K = sum(sum(rgb2gray(Image.cdata)==255));
percentageofwhite(y) = K/numel(rgb2gray(Image.cdata))*100;
delete(findall(gcf,'type','text'))
txt=text(0.0,0.95,sprintf('White Space = %0.3f%%',percentageofwhite(y)),'Units','normalized');
y=y+1;
xlim([-5*d d*5])
ylim([-5*d d*5])
end
hold off
xlabel('My x label')
ylabel('My y label')
zlabel('My z label')
rotate3d on

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by