MATLAB Answers

Plot two functions with different pause rates at same time.

2 views (last 30 days)
Hello,
I'm trying to plot these two sets of data that are different lengths, but cover the same amount of ground if that makes sense. The truncatedXYZ will plot a lot faster with timesteps(pauses) of around 0.01 whereas the jittercheck will plot slower with timesteps(pauses) of around 0.1. I'm trying to get it to plot the truncatedXYZ following that pause rate and plot the jittercheck following the other pause rate at the same time and on the same graph. When I do this, it only prints the first 239 points for truncatedXYZ instead of the full 2987 because the jittercheck has already finished all of its points. I commented out the pauses because they would make it take too long to check. The final result should be the same shape in red and black. Thank you for any tips or help you can give me.
frames = 239;
trunk = 2987;
hold on
ivals = 1:trunk;
jvals = 1:frames;
for K = 1 : length(ivals)
i = ivals(K);
j = jvals(K);
plot(truncatedXYZ.rel_x(i),truncatedXYZ.rel_y(i),'or')
xlim([7.4 8.6])
ylim([2.5 5])
%pause(truncatedXYZ.timestep(i))
plot(jittercheck(j,2),jittercheck(j,3),'ok')
xlim([7.4 8.6])
ylim([2.5 5])
%pause(jittercheck(j,6))
end

Accepted Answer

Mohammad Sami
Mohammad Sami on 15 Sep 2021
Edited: Mohammad Sami on 15 Sep 2021
You can try something like plotting j every few steps.
frames = 239;
trunk = 2987;
hold on
lastjplotted = 0;
for i = 1:trunk
j = ceil(i*frames/trunk);
plot(truncatedXYZ.rel_x(i),truncatedXYZ.rel_y(i),'or');
xlim([7.4 8.6]);
ylim([2.5 5]);
if(j > lastjplotted)
plot(jittercheck(j,2),jittercheck(j,3),'ok');
xlim([7.4 8.6]);
ylim([2.5 5]);
lastjplotted = j;
end
pause(truncatedXYZ.timestep(i));
end

More Answers (0)

Community Treasure Hunt

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

Start Hunting!