pcolor issue with irregular grid

18 次查看(过去 30 天)
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