patch.m is the correct function to use.
Basic Imagesc Question -- 2D Matrix
3 views (last 30 days)
I have a 2D matrix. I wish to plot it in a particular way.
The first col, I wish to represent the values on the y-axis. The second col, I wish to use to color code the plotted values.
The matrix changes over time, t. Time runs along the x-axis.
for t = 1: T
c = NaN(2,5);
c(1,:) = rand(1,5); %this vector should be the y-axis
c(2,:) = randi(10,1,5); %this vector should color code c(1,:)
c = sort(c,2);
I think this is very simple, but just cant get it working! Can anyone help? thank you.
More Answers (1)
Walter Roberson on 9 Sep 2011
I am unclear as to what your x axis is?
Your sort(c,2) sorts each row independently, which destroys any implicit link you might have of the color in c(2,K) corresponding to the y in c(1,K). Is that what you want? Or were you trying to sort by y value but preserve the color mapped to each y ?
I was thinking that perhaps your x axis is implicitly the column index in to the matrix, but if that is the case then it would not seem right to be sorting the y ?
You effectively have a vector of y values and a vector of corresponding colors, but imagesc() is for rendering 2D matrices colored per-pixel. Is a bar graph perhaps a better representation for your data?