How do I scatter twice on the same graph?
Show older comments
Hello,
I have 2 vectors with numbers: velocity(815x1) and velocityTimes(815x1). Velocity is calculated, among the other parameters, with a variable N which also changes the way it looks when scattered.
I need to scatter velocity and velocityTimes once, change N, and then on the same graph scatter it again with the new N.
However I can't seem to get it right.
What I'm trying to do is this:
n = 2
figure(1)
scatter(velocityTimes,velocity)
hold on
n = 150
scatter(velocityTimes,velocity)
But it only scatters the first one, with n=2. How do I fix it?
Thanks very much in advance!
7 Comments
Walter Roberson
on 29 Apr 2018
Your code outline does not show velocity being recomputed. Also, "n" and "N" are not the same.
Recompute velocity (see example code)
velocity = ones(815,1); % velocity vector
n = 2;
velocity = velocity*n; % example formula
figure(1)
scatter(velocityTimes,velocity)
n = 150; % redefine n
velocity = velocity*n; % recomputate velocity!!!
hold on
scatter(velocityTimes,velocity)
hold off
dpb
on 29 Apr 2018
And the result is?
Nothing appears amiss other than the plots are going to be very uninteresting given the data and operation thereon but certainly should be two shown. Perhaps if you physically change the color of the second to ensure you can distinguish the two???
Walter Roberson
on 30 Apr 2018
velocity*n the first time is going to be all 2s, which would lead to a horizontal series at 2.
velocity*n the second time is going to multiply those 2s by 150, leading to all 300s, which would then give a horizontal series at 300.
Are you sure you want the two different n values to be multiplied together? Or should you be taking a copy of the original velocity and use that to calculate the second velocity ?
Guilherme de Melo
on 17 Aug 2024
Hello. I am trying to plot similar multiple scatter at the same plot, but it showing error.
scatter(time_vector_ev2,baz_lines_ev2,50,back_azm_ev2_error, 'LineWidth',1.5)
hold on
scatter(time_vector_ev1,baz_lines_ev1,50,back_azm_ev2_error,"filled", 'LineWidth',1.5)
the time_vector_ev2 and baz_lines_ev2 has 1x33 size, while time_vector_ev1 and baz_lines_ev1 is 1x9. They are the same information. However, the time_vector_ev1 and baz_lines_ev1 has just a short information range of the time_vector_ev2 and baz_lines_ev2 that should be highlighted on plot. So, I am using the "filled" to change the circles. The time_vector_ev1 and baz_lines_ev1 would be the values from 13 to 21 position of the 1x33 matrix referent to the time_vector_ev2 and baz_lines_ev2.
Does someone know how I can do there? Thanks in advance!
Walter Roberson
on 17 Aug 2024
The number of elements in x and y must match the number of elements in sz (with some exceptions for the case of matrix x and y and vector sz.)
If back_azm_ev2_error matches the size of time_vector_ev2 for the first call, then it is not going to match the size of time_vector_ev1 for the second call, but you used back_azm_ev2_error as the sz for both calls.
Guilherme de Melo
on 17 Aug 2024
Yes, that was the so simple problem that I did not see. thank you very much
Answers (1)
Roee Ben Shlomo
on 3 May 2018
0 votes
Categories
Find more on Scatter Plots 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!