【问题标题】:Making a few changes to my contour plot in matlab 2015在 matlab 2015 中对我的等高线图进行一些更改
【发布时间】:2016-02-22 01:49:01
【问题描述】:

我有一个数据文件,其中有 3 列,一列用于 x 轴上的位置,另一列是时间,第三列是温度。

因此,我在 x 和 time 中对温度进行了插值,以获得一个连续插值多项式句柄。

然后我在所有 x 和时间值上创建了一个网格,并获得了所有这些值的插值多项​​式值。

然后我在所有这些插值上绘制了等高线图。

但是我在这里看到了一些奇怪的行为。正如您在图中看到的那样,我的 x 值从 10 到大约 1300 不等。所以如果我保留这些 x 值,我会到处看到蓝色区域。但是当我将这个范围缩小到 200-1300 时,我仍然到处都能看到相同的蓝色区域。即使我将其更改为任何其他值,如图所示的整个蓝色区域仍然存在。

所以我的问题是,我希望在轮廓的顶部边界上方有一个白色区域,你可以看到它大约在 1200 左右,而在 x 轴上轮廓的尾端下方有一个类似的白色区域,大约在可能是200左右。

但我想将蓝色区域保留在轮廓停止的三角形区域中,因为在时间轴(即 x 轴)上指定的不同时间尺度上,x=400-1200 处有材料。

P.S.:为了清楚起见,y 轴是 x 值,x 轴是时间值,轮廓对应于 z 轴上的温度,通过在 matlab 中使用scatterInterpolant 函数对x 和时间进行插值获得。

这是我正在使用的脚本:

clear all; close all; clc;
load temperature.txt;
time = temperature(:,1);               % This column contains the time
x = temperature(:,2);                  % This column contains the x values.
temperature_system = temperature(:,3); % This column contains the temperatures.

pos = temperature_system < prctile(temperature_system,41.967695);
time(pos) = [];
x(pos) = [];
temperature_system(pos) = [];

pos = (temperature_system > prctile(temperature_system,97));
time(pos) = [];
x(pos) = [];
temperature_system(pos) = [];

X1 = [time x];


F = scatteredInterpolant(X1,temperature_system);
x1 = linspace(min(x),max(x),100);
x2 = linspace(min(time),max(time),100);
[X,Y] = meshgrid(x2,x1);
Z = F(X,Y);
% plot3(x1,x2,F(x1,x2));
f1 = figure(1);
set(f1,'renderer','zbuffer');
%surf(X,Y,Z);
%ezcontourf(F)
[C,h] = contourf(X,Y,Z);
shading flat;
colormap(jet);
q = colorbar;
% cmap = colormap;
% cmap(1,:) = [1,1,1];
% colormap(cmap);

这是我的图,没有任何修改:

如果我删除带有白色区域的蓝色区域,这就是我的图片。

请注意图表开始的三角形区域,现在是白色,之前是蓝色,我想保留这个,但我该怎么做?

【问题讨论】:

    标签: matlab plot


    【解决方案1】:

    我想这就是你要找的。如果不是,请告诉我。我只是说,如果温度在某一时刻或所有空间的所有时间都超出范围,请忽略它。

    function StackOverflow
    
    %Setting up variables, since I don't have the data
    x = 1300*rand(1500, 1);
    t = 45*rand(size(x));
    T = 3000*exp(-((x - 650).^2/(2*(650/3)^2)) - ((t - 22.5).^2/(2*(22.5/3)^2)));
    
    %Some criteria for ignoring below
    TLow = 500;
    
    %Create the interpolant on a regular grid
    F = scatteredInterpolant([t, x], T);
    xr = linspace(min(x),max(x),100);
    tr = linspace(min(t),max(t),100);
    
    [tr,xr] = meshgrid(tr,xr);
    Tr = F(tr,xr);
    
    %Is the data below the criteria for all points in space at a specific time
    emptyTime = all(Tr < TLow,1);
    
    %Is the data below the criteria for all time at a point in space
    emptySpace = all(Tr < TLow, 2);
    
    %If there is no data set it to nan
    [emptyTime, emptySpace] = meshgrid(emptyTime, emptySpace);
    Tr(emptyTime | emptySpace) = nan;
    
    %Do plotting stuff
    f1 = figure(1);
    set(f1,'renderer','zbuffer');
    
    [C,h] = contourf(tr,xr,Tr);
    shading flat;
    colormap(jet);
    q = colorbar;
    
    end
    

    【讨论】:

    • 非常感谢,我现在知道了。我只是用 find 来查找 Z 中所有为零的位置,然后用 nan 替换它们。我现在一切都很好。非常感谢您的建议。
    • 没问题。你能发布最终的轮廓,只是因为我有兴趣吗?
    • 我在编辑后发布了新图表,但我仍在尝试平滑边缘。由于 nan 值,现在它们是不均匀的,有没有办法在 matlab 中做到这一点?
    • 我已经发布了代码和数据请看一下。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-08
    • 1970-01-01
    相关资源
    最近更新 更多