Scatter Plot with nan values

10 views (last 30 days)
AB
AB on 23 Aug 2016
Answered: Walter Roberson on 23 Aug 2016
Hi
I have 3 groups, say A, B and C in separate arrays of dimensions say 20 by 1, 30 by 1 and 50 by 1 respectively. I want to plot a scatter plot of these values with a line indicating the mean. How can this be done. When I join A,B and C to fill up empty spaces by nan values, i am unable to get the scatter plot. Any simple code to plot the scatter plot and mean?

Answers (1)

Walter Roberson
Walter Roberson on 23 Aug 2016
You cannot scatter plot those. scatter plot requires 2 dimensions, but you only have one dimension.
Perhaps you want something like
hA = scatter( 1 * ones(length(A),1), A);
hold on
hB = scatter( 2 * ones(length(B),1), B);
hC = scatter( 3 * ones(length(C),1), C);
m = mean([A; B; C]);
hm = line([1 3], [m m])
legend([hA, hB, hC, hm], {'A', 'B', 'C', 'mean'});
Or perhaps you just want to use boxplot()

Categories

Find more on Data Distribution 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!