Plotting at set intervals in a for loop
Show older comments
I'm plotting partical postions in a for-loop with t as followed:
t = 0:timeStep:timeStep*nrOfTimeSteps
Now I think the bulk of my code is not required for this question. I want to plot the particle positions in a scatter plot at four set intervals namely [0, 1/4, 1/2, 3/4, 1] of the total time. Everything I've tried so far plots either 0 points, the particle positions at the end, or all the positions at each time step (hold on).
What is the way to implement this within my loop?
Thanks in advance
4 Comments
Kirby Fears
on 30 Sep 2015
Are you trying to scatterplot Y values for X between [0,1/4] in one plot, then repeat for X between [1/4,1/2] in a second plot, etc?
NotSoWiseman
on 30 Sep 2015
Edited: NotSoWiseman
on 30 Sep 2015
Shigeo Nakajima
on 5 Jan 2017
If I was looking for what you stated (Kirby Fears), how would I do that?
Kirby Fears
on 5 Jan 2017
Edited: Kirby Fears
on 5 Jan 2017
Shigeo,
This will plot all (X,Y) position pairs for time between 0-1/4 in one plot, time between 1/4-1/2 in a second plot, etc.
T=0.1:0.1:10;
X=rand(numel(T),100);
Y=rand(numel(T),100);
stepSize=numel(T)/4;
tPoints=round(0:stepSize:numel(T));
for t = 1:(numel(tPoints) - 1),
xVals = X(tPoints(t)+1:tPoints(t+1),:);
yVals = Y(tPoints(t)+1:tPoints(t+1),:);
figure();
scatter(xVals(:),yVals(:));
end,
Accepted Answer
More Answers (0)
Categories
Find more on Solver Outputs and Iterative Display in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!