MATLAB: Scatter plot with categorical x axis

scatter

I need to produce scatter plot with categorical x axis.
I used this script:
figure(1)
x=['pixels'];
y=Tmean_split.pixels;
scatter(x,y)
in which the size of Tmean_split.pixels is 6*1.
I recieve this error:
Must supply X and Y data as first arguments.
Any idea why this error happening?

Best Answer

'pixels' isn't an allowable argument for the x value position...it's a char() array string array and that's confusing the input parser inside scatter() -- it's trying to interpret the character string argument as one of the trailing optional arguments like the colorspec or the like, but as the documentation says, the x, y data have to be supplied before any of those.
scatter() also MUST have both x and y data arguments; you can't just give it a y vector like plot(). It will accept a categorical array as the X axis value, but you'll have to define it for the six categories to which each of the y variable values belongs to do so.
Related Question