Why reshaping the matrix gives entirely different plots while using pcolor()
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Walter Roberson
2022년 4월 6일
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
Walter Roberson
2022년 4월 7일
imagesc('XData', [M(1,1), M(end,end)], 'YData', [N(1,1),N(end,end)], 'CData', P)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!