2
votes

I have three vectors of data; first column is axis x, second column axis y and third column is the measured data point value v:

x = [1  2  3 4  5];
y = [2  3  4 5  6];
v = [0 -1 +2 3 -5];

Is there a way to plot this in matlab and color the data points according to their value? I tried with scatter, but that doesn't give color coding.

2
do you mean for example, you want darker colour for lower values and lighter colour for higher values? - GameOfThrows

2 Answers

4
votes

Just use scatter, it can accept values for each point. Just set the size of each point, set it to be filled, turn on the colorbar and that's it. Just please don't use the jet colormap...

x = [1  2  3 4  5];
y = [2  3  4 5  6];
v = [0 -1 +2 3 -5];

pt_sz = 30;

colormap parula
scatter(x, y, pt_sz, v, 'filled');
colorbar;
grid on

enter image description here

-1
votes

You can try pcolor. It works like

z=rand(4,4);
pcolor(R,C,z);

Where z is a matrix storing the data (your v), R is the row (your x) and C is the column (your y).

edit: why downvote? please tell what's wrong so that I can correct it.