Why reshaping the matrix gives entirely different plots while using pcolor()
1 view (last 30 days)
Show older comments
Hello,
I was trying to plot 3 variables with two of them representing the X and Y axes while the third one is used to denote the color, using the pcolor function. I however find that whenever I change the dimensions of the matrix by reshaping them and try plotting again, I get entirely different plots. I was wondering why that is happening - after all its the same datapoints which are being plotted against each other everytime (no matter what the dimension of the matrix is) , how come a mere change in the dimensions of the matrix give different results?
Following is the code which I tried (given for example):
M = randi([1 100],13, 21); % original matrices
N = randi([200 500],13, 21);
P = randi([700 1000],13, 21);
M1 = reshape(M,3,[]); % reshaped matrices from the original matrices
N1 = reshape(N,3,[]);
P1 = reshape(P,3,[]);
M2 = reshape(M,39,[]); % reshaped matrices from the original matrices
N2 = reshape(N,39,[]);
P2 = reshape(P,39,[]);
figure(1);
pcolor(M,N,P);
figure(2);
pcolor(M1, N1, P1);
figure(3);
pcolor(M2, N2, P2);
Thank you.
0 Comments
Accepted Answer
Walter Roberson
on 6 Apr 2022
pcolor() is equivalent to surf() followed by view(90) .
surf() does not use the input data directly to compute face color. Instead, surf() uses the input data as indicating the vertices, and does a bilinear interpolation to get the value to use for the face color.
When you reshape() you change the relative order of the nodes, and so change which vertices are combined for a particular face. But because of the interpolation to get the actual face color, that changes the face colors.
7 Comments
Walter Roberson
on 7 Apr 2022
imagesc('XData', [M(1,1), M(end,end)], 'YData', [N(1,1),N(end,end)], 'CData', P)
More Answers (0)
See Also
Categories
Find more on Discrete Data Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!