Alex Liu
Alex Liu

Reputation: 11

2D color plot using a limited dataset

I couldn't find a solution after trying for a long time.

I have 3 columns of data: x, y, and the stress value (S) at every point (x,y). I want to generate a 2D color plot displaying continuous color change with the magnitude of the stress (S). The stress values increase from -3*10^4 Pa to 4*10^4 Pa. I only have hundreds of data points for an area, but I want to see the stress magnitude (read from the color) at every location (x, y). What Matlab command should I use?

I want to make a 2D color plot showing stress magnitude (S) at every location (x, y) based on continuous color change using limited data points

Upvotes: 0

Views: 1111

Answers (3)

Serge
Serge

Reputation: 1

To further contribute on Gunther Struyf answer; assuming it is a FEM analysis you may already have a connectivity matrix say 'M' and 'x' 'y' column vectors with node coordinates. Stress values at the nodes may be contained in a column vector 'S'; then you may use the patch function as stated above:

patch('faces',M,'vertices',[x(:) y(:)],'facevertexcdata',S(:),'FaceColor','interp');

and you will have a 2D plot of your data similar to the one posted by Gunther Struyf.

Upvotes: 0

Gunther Struyf
Gunther Struyf

Reputation: 11168

I'd use patch with interpolated coloring:

% some data, x/y are random
N = 50;
x = rand(N,1);
y = rand(N,1);
S = sin(2*x)+y;

% plotting
tr = delaunay(x,y);
trisurf(tr,x,y,zeros(N,1),S,'FaceColor','interp');
view (2)

enter image description here

Upvotes: 2

Fabian Tamp
Fabian Tamp

Reputation: 4536

Take a look at surf and mesh in the MATLAB documentation

Upvotes: 1

Related Questions