Why reshaping the matrix gives entirely different plots while using pcolor()

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

Walter Roberson
Walter Roberson il 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 Commenti
Mathan
Mathan il 7 Apr 2022
It still gives out the same result (i.e. different plots whenever reshaping is done). The code is as follows:
M = randi([1 100],13, 21);
N = randi([200 500],13, 21);
P = randi([700 1000],13, 21);
M1 = reshape(M,3,[]);
N1 = reshape(N,3,[]);
P1 = reshape(P,3,[]);
M2 = reshape(M,39,[]);
N2 = reshape(N,39,[]);
P2 = reshape(P,39,[]);
M3 = reshape(M.',1,[]);
N3 = reshape(N,1,[]);
P3 = reshape(P,1,[]);
figure(1);
imagesc('XData', [M(1,1), M(end,end)], 'YData', [N(1,1),N(end,end)], 'CData', P)
figure(2);
imagesc('XData', [M1(1,1), M1(end,end)], 'YData', [N1(1,1),N1(end,end)], 'CData', P1)
figure(3);
imagesc('XData', [M2(1,1), M2(end,end)], 'YData', [N2(1,1),N2(end,end)], 'CData', P2)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Discrete Data Plots in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by