Scatter Plot Vectors of Different Lengths

14 views (last 30 days)
Hello, I am trying to make a scatterplot for some data. The data is a bit more complicated and large, so I have recreated a sample below on a smaller level for the sake of understanding what I am trying to do.
I have 3 experiments that each have data from 4-6 trials. I get an error that the vector size must be the same when I use the scatter function.
Example:
Experiment 1 Data (in seconds) [ 33, 43, 45, 34]
Experiment 2 Data (in seconds) [ 44, 47, 43, 48, 49, 46]
Experiment 3 Data (in seconds) [ 54, 47, 56, 57, 49]
I want the X axis to show Experiment 1, 2, 3 and the Y axis to show time with the points scattered based on their time in seconds while staying within their respective experiment group on the x axis.
Thanks!

Accepted Answer

Hayden Garmon
Hayden Garmon on 13 Aug 2020
Edited: Hayden Garmon on 13 Aug 2020
Does this work?
vec1= [ 33, 43, 45, 34];
vec2= [ 44, 47, 43, 48, 49, 46];
vec3= [ 54, 47, 56, 57, 49] ;
plot(ones(1,length(vec1)),vec1,'x')
hold on
plot(2*ones(1,length(vec2)),vec2,'o')
plot(3*ones(1,length(vec3)),vec3,'*')
legend('Exp 1','Exp 2','Exp 3')
xlim([-1,5])

More Answers (0)

Community Treasure Hunt

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

Start Hunting!