2
votes

Scatter Plots in MatLab. I can create a scatter plot with x and y arrays being the same size as follows:

function RasterTest()

    clear all % clear memory
    clc; % clear command window
    close all; % close any figure windows that are open

    x=[1 2 3]; % x positions of the charges
    y=[4 8 2]; % y positions of the charges

    scatter(x,y,'filled')
    axis square

end

However, what if I want every x to have multiple y values? I.e. the array sizes are different. I think this is actually called a raster plot but MatLab doesn't seem to have something to do this?

Any help would be great :).

2
What I ended up doing is using hold on and overlaying graphs which works fine. pccofre answers seems to be correct too. - ale

2 Answers

3
votes

plot allows diferent size vectors

plot(x,[sin(x);2*sin(x);3*sin(x)],'*')
2
votes

When the array sizes are different, how can you map every y value to the according x value? It's ambigous.

When you generate your data, just make sure that you insert every pair of values into the x and y arrays:

x = [1 2 3 1 3];
y = [3 4 5 6 7];

In the above example you got multiple points for the x values 1 and 3.