0
votes

I have 11 1x50 matrices that contain densities. The first looks like [20, 20, 20... 20] and represents time=0. The second looks like [20, 19, 22,..], etc. and represents time=100. These continue to vary until t=1000.

What I'm hoping to do is to create a plot with the elements' position on the x-axis (50 positions for the 50 pieces of data in each) and time (0-1000) on the y-axis. Ideally, I'd like the plot to be completely filled in with color densities, and a colorbar on the side that shows what densities the color range represents.

Any help would be greatly appreciated!

Sort of inspired by: http://www.chrisstucchio.com/blog/2012/dont_use_scatterplots.html

2
Any ideas @rayryeng? You were very helpful yesterday!LuckyPenny
Hello again. Is this a 2D matrix that contains these 11 vectors, or are these 11 individually named vectors? BTW, the answer to this is very easy.rayryeng
That's good to hear! I have 11 individually named vectors.LuckyPenny
Yuck :(. OK, I'll leave it to you to construct these into a 2D matrix. Assuming that, I'll write my answer. Give me a few minutes.rayryeng
Do you really have 11 separated 1x50 matrices? It's much better to arrange them into a 11x50 matrixLuis Mendo

2 Answers

2
votes

Looking at the comments, it will be easier to stack these vectors into a 2D matrix. You have 11 individually named vectors. Assuming that your vectors are named vec1, vec2, vec3, etc., create a 2D matrix A that stacks these vectors on top of each other. Also, you'll need to include an extra row and column at the end of this matrix that contains the minimum over all of your vectors. The reason why this is will be apparent later, but for now take my word for it as this is what you need.

In other words:

A = [vec1; vec2; vec3; vec4; vec5; vec6; vec7; vec8; ...
     vec9; vec10; vec11];
minA = min(A(:));
A = [A minA*ones(11,1); minA*ones(1,51)];

As such, the first row contains the information at time 0, the next row contains information at time 100, etc. up to time 1000.

Now that we have that finished, we can use the pcolor function to plot this data for you. pcolor stands for pseudo-coloured checkerboard plot. You call this by doing:

pcolor(A);

This will take a matrix stored in A and produce a checkerboard plot of your data. Each point in your matrix gets assigned a colour. The colours get automatically mapped so that the least value gets mapped to the lowest colour while the highest value gets mapped to the highest colour. pcolor does not plot the last row and last column of the matrix, but pcolor does use all of the data in the matrix. In order to ensure that the colours get properly mapped, we need to pad your matrix so that the last row and last column get assigned to the smallest value over all of your vectors. As you want to plot all values in the matrix, that's why we did what we did above.

Once we do this, we'll need to modify the X and Y ticks so that it conforms to your data. As such:

pcolor(A);
set(gca, 'XTick', 0.5:5:51.5);
set(gca, 'XTickLabel', 0:5:50);
set(gca, 'YTick', 1.5:11.5);
set(gca, 'YTickLabel', 0:100:1000);
xlabel('Sample Number');
ylabel('Time');
colorbar;

What the code does above is that it generates a checkerboard pattern like what we talked about. This labels the Sample Number on the x axis while time is on the y axis. You'll see with the two set commands that I did, this is a bit of a hack. The y axis by default labeled the ticks going from 1 - 12. What I did was that I changed these labels so that they go from 0 to 1000 in steps of 100 instead and I also removed the tick of 12. In addition, I have made sure that these labels go in the middle of each row. I do this by setting the YTick property so that I add 0.5 to each value going from 1 - 11. Once I do this, I then change the labels so that they go from 0 - 1000 in steps of 100. I also do the same for the x axis in a similar fashion to the y axis. I then add a colorbar to the side as per your request.

Following the above code, and generating random integer data that is between 13 and 27 as per your comments:

A = randi([13,27], 11, 50);
minA = min(A(:));
A = [A minA*ones(11,1); minA*ones(1,51)];

We get:

enter image description here

Obviously, the limits of the colour bar will change depending on the dynamic range of your data. I used randi and generated random integers within the range of 13 to 27. When you use this code for your purposes, the range of the colour bar will change depending on the dynamic range of your data, but the colours will be adjusted accordingly.

Good luck!

2
votes

Assuming you have (or can arrange to have) all those vectors as columns of a 11x50 matrix:

A = randi(100, 11,50); %//example data

you can just use

imagesc(1:50, 0:100:1000, A)
colorbar
axis xy %// y axis increasing, not decreasing

Example:

enter image description here