Hotdog2000
Hotdog2000

Reputation: 125

Plotting Areas from an Integer Valued Matrix in MATLAB

Suppose I have some NxM array called L in which each entry contains one of four integers, let's say 0,1,2,3. Each number is grouped within the array, i.e. The upper right side of L will be entirely 1, and the lower left will be all 2 and the middle will be all 0, etc.

Is there any way to draw an area graph using MATLAB such that the graph will have axes ranging from 0 to N on one axis and 0 to M on the other, where areas corresponding to a specific integer in the matrix will be filled in with different colors in the same location on the graph?

The result should look something like this: Link to Image

I've been looking for a solution to this problem, but I can't seem to find some sort of easy answer anywhere.

Let me know if I should clarify anything else.

Upvotes: 1

Views: 57

Answers (1)

Luis Mendo
Luis Mendo

Reputation: 112699

How about a simple imagesc?

L = [0 0 0 1 1 1
     0 0 1 1 1 1
     0 0 0 1 1 2
     0 0 1 1 2 2
     0 0 0 2 2 2
     3 3 3 3 2 2
     3 3 3 3 3 3]; %// example data
cmap = [1 .5 .5    %// light red
        .5 1 .5    %// light green
        .5 .5 1    %// light blue
        .5 .5 .5]  %// grey
imagesc(L);        %// show image
colormap(cmap)     %// use colormap
axis image         %// set same scale on both axes

enter image description here

Upvotes: 2

Related Questions