필터 지우기
필터 지우기

pcolor issue with irregular grid

조회 수: 18 (최근 30일)
Amin
Amin 2020년 12월 17일
댓글: Amin 2020년 12월 22일
I have been spending way too much time and would appreciate your insight and comments.
I am using “pcolor” to plot my data on an irregular grid (regularizing it is not an option).
-when I plot the even rows of my X, Y, and data the figure is what I expect (figure 1).
-when I plot the odd rows of my X, Y, and data the figure is what I expect (figure 2).
-when I plot the all rows of my X, Y, and data the figure is NOT what I expect (figure 3).
**figure 3 should be similar to figures 1&2 (basically those 2 superimposed).
the data, X, and Y are attched.
Thanks again.
clear all; close all; clc
load('C:\Desktop\Test\X.mat');
load('C:\Desktop\Test\Y.mat');
load('C:\Desktop\Test\data.mat');
% replaceing zeros with NAN
X(X == 0) = NaN;
Y(Y == 0) = NaN;
data(data == 0) = NaN;
% choosing even rows
X1 = X(2:2:end,:);
Y1 = Y(2:2:end,:);
data1 = data(2:2:end,:);
% choosing odd rows
X2 = X(1:2:end,:);
Y2 = Y(1:2:end,:);
data2 = data(1:2:end,:);
figure(1)
h1 = pcolor(X1,Y1,data1);
set(h1,'edgecolor','none');
figure(2);
h2 = pcolor(X2,Y2,data2);
set(h2,'edgecolor','none');
figure(3);
h3 = pcolor(X,Y,data);
set(h3,'edgecolor','none');
  댓글 수: 2
Mathieu NOE
Mathieu NOE 2020년 12월 20일
hi
have to figure out why pcolor is doing that
with imagesc I don't have the problem
clear all; close all; clc
load('X.mat');
load('Y.mat');
load('data.mat');
% replaceing zeros with NAN
X(X == 0) = NaN;
Y(Y == 0) = NaN;
data(data == 0) = NaN;
% choosing even rows
X1 = X(2:2:end,:);
Y1 = Y(2:2:end,:);
data1 = data(2:2:end,:);
% choosing odd rows
X2 = X(1:2:end,:);
Y2 = Y(1:2:end,:);
data2 = data(1:2:end,:);
figure(1)
h1 = imagesc(data1);
% set(h1,'edgecolor','none');
figure(2);
h2 = imagesc(data2);
% set(h2,'edgecolor','none');
figure(3);
h3 = imagesc(data);
% set(h3,'edgecolor','none');
Amin
Amin 2020년 12월 20일
편집: Amin 2020년 12월 20일
Thanks for giving it a try. unfortunately, imagesc is out of question. pcolor(data) just like imagesc(data) will work if true coordinates are not included (they produce the image base on indices but the image will be much noisier because of duplicates). The problem is that imagesc cannot handle irregular X and Y and pcolor cannot handle all X and Y together when in principle it should (can only do even ones together or add ones together using the true X,Y).
cheers,

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2020년 12월 20일
surf(X(1:2:end,:), 'edgecolor', 'none')
and rotate it a bit, and you can see that the bulk of it is a single titled plane.
surf(X(2:2:end,:), 'edgecolor', 'none')
is likewise a single titled plane.
Now
surf(X, 'edgecolor', 'none')
and you will observe a thick wedge.
So although even X and odd X individually form consistent planes, when you take both together they do not form a single plane. When used as coordinates, pcolor would have to try to compensate.
Note: pcolor is surf() followed by view(2), together with some logic that sets the Z coordinates of the surf to all 0.
  댓글 수: 3
Walter Roberson
Walter Roberson 2020년 12월 21일
load X
load Y
load data
X(X == 0) = NaN;
Y(Y == 0) = NaN;
data(data == 0) = NaN;
mask = ~(isnan(X) | isnan(Y) | isnan(data));
F = scatteredInterpolant(X(mask), Y(mask), data(mask));
%trim down to useful part of data
[~, idx] = max(X(:));
[R, C] = ind2sub(size(X), idx);
lastC = C-2; %some of the last couple of columns dip down
Xsub = X(:,1:lastC);
minx = min(Xsub, [], 'all');
maxx = max(Xsub, [], 'all');
Ysub = Y(:,1:lastC);
miny = min(Ysub, [], 'all');
maxy = max(Ysub, [], 'all');
xv = linspace(minx, maxx, lastC);
yv = linspace(miny, maxy, size(X,1));
[XG, YG] = ndgrid(xv, yv);
Z = F(XG, YG);
h = pcolor(XG, YG, Z);
h.EdgeColor = 'none';
In theory this takes all of the data into account. However, it interpolates data coordinates, and in theory it would work out something like taking the bottom (even-numbered) layer and shifting it to the left, and then merging the two sheets. The results look okay, but before using the [XG, YG, Z] data for serious analysis, you should think more about how the triangulation process works to make sure that you really are getting contributions from both half.
Amin
Amin 2020년 12월 22일
This seems to be working but like you said I need to look into if full contribution is there or not. Thanks again.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Geographic Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by