2

对 matlab 相对较新,希望对我的项目的最佳选项提供一些输入。

我在办公室周围的设定位置有几个温度探头,我必须在平面图图像上显示热图。(有点像我想要实现的,点是探针,这将覆盖在平面图上)

目前我正在寻找组织和绘制数据的最佳方式。

我有一个来自每个探头的 csv 文件,其中包含一个timestamp列和一个温度列。每个 csv 文件可能有大约 3 个月/2000 个读数。

目前,我将来自不同探针的所有 csv 文件导入到单元格中,并按与其位置相对应的数字进行组织。Sodata{1}{1}包含时间戳并data{1}{2}包含位置 1 的探头温度。data{2}用于位置 2,依此类推。这是存储它的好方法吗?

最终,我需要能够在查看地图时寻找或玩不同的时间。但目前我只是在寻找绘制它的最佳选择。

我有平面图图像,我知道我必须找到位置的像素/xy 表示,但那又如何呢?

绘制所有这些探针的最佳方法是什么。我打算使用 surf(顶视图),但这需要 x/y 坐标的数组吗?

我的想法是将位置存储为静态整数、loc1X= ..、loc1y= 等,然后制作一个类似的数组,[loc1X loc1Y data{1}{2}(1); loc2X loc2Y data{2}{2}(1)]但 surf 仍然说 Z 需要是一个要绘制的数组。

4

2 回答 2

1

假设您的位置没有设置为在矩形网格中相距正好 1m(那将是一个奇怪的办公室......),您将面临必须通过分散的数据点插入表面的问题。Matlab 函数TriScatteredInterp将是您所需要的。只需按照链接中的示例进行一些更改:

x = [x values of your locations]
y = [y values of your locations]
z = [all heat readings for all x,y for a single timestamp]

F = TriScatteredInterp(x,y,z);

并像示例中一样绘制。您必须为所有时间戳执行此操作,因此,在伪代码中:

x = [x values of your locations]
y = [y values of your locations] % assuming they don't change

F = cell(numel(data{1}{1}),1);
for t = 1:numel(data{1}{1}) % loop through all time stamps

    z = cellfun(@(p)p{1}(t), data);
    F{t} = TriScatteredInterp(x,y,z);

end

然后您可以绘制第一个F{1}并在图中添加一个滑块以选择不同的时间。

请注意,这假定所有节点都以相同的时间戳收集数据。如果不是这种情况(我怀疑不是),你必须再做一步:为每个 XY 点在时间维度上创建一个插值。

这可以很容易地使用spline. 例如,

pp = spline(data{1}{1}, data{1}{2});

为第一个位置创建一个spline遍历所有数据,这样

z = ppval(pp, [any random time within the interval]) 

给出区间内任何时间的热量的插值. 您可以通过发出

z = spline(data{1}{1}, data{1}{2}, [any random vector of times] );

所以,总结一下:

% interpolate over time

% NOTE: use the maximum first time, and the minimum last time, 
% to ensure these endpoints are included in all splines.
minTime = max( cellfun(@(p)p{1}(1), data) ); 
maxTime = min( cellfun(@(p)p{1}(1), data) );

trange = minTime : [some step] : maxTime;

npts = size(data,1);
z    = cell(npts,1);
for ii = 1:npts
    % creates interpolation for H(t) at equal times 
    % trange for location ii
    z{ii} = spline(data{ii}{1}, data{ii}{2}, trange);
end

% interpolate spatially

x = [x values of your locations]
y = [y values of your locations] % assuming they don't change

nts = numel(trange)
F = cell(nts,1);
for t = 1:nts    

    zed = cellfun(@(p)p(t),z);
    F{t} = TriScatteredInterp(x,y, zed);

end

% ... and further plotting commands
于 2012-10-19T06:35:45.023 回答
0

这是您第二个问题的答案(在上面的评论中):

% get a list of all initial sampling times for all sensors
first_times = cellfun(@(x)   x{1}(1), data);
last_times  = cellfun(@(x) x{1}(end), data);

% find the max/min of these times. 
% NOTE: the order of max/min might be counter-intuitive!
[m, im] = max(first_times);
[M, iM] = min(last_times);

% 'im' contains the number of the data set which has the latest initial
% sampling time. 'iM' contains the number of the data set which has the 
% earliest final sampling time.

% Now find the indices to the actual sampling times in all data sets
% that correspond to these initial and final times:

proper_first = cellfun(@(x) find(x{1}==m,1), data);
proper_last  = cellfun(@(x) find(x{1}==m,1), data);

% index times and data in dataset k like so: 
data{k}{1}( proper_first(k) : proper_last(k) ) % times
data{k}{2}( proper_first(k) : proper_last(k) ) % data

现在为了将来参考,最好只问一个关于 SO 的新问题;在一个线程中询问您的所有问题通常被认为不是一种好的做法,因为这将使任何未来遇到您遇到的相同问题的谷歌用户都很难找到。

于 2012-11-29T10:38:12.267 回答