Matlab的。使用isequal来比较数组的动态大小

时间:2015-04-07 10:56:07

标签: arrays matlab dynamic unique equality

我有一个包含许多温度曲线的数据集。其中一些记录在同一位置并包含不同的数据,但不幸的是有时会出现重复的配置文件。我想删除重复的数据,而不删除在不重复的同一位置完成的配置文件。为了做到这一点,我循环每年的数据,并检查该年内所有配置文件的位置是否是唯一的。然后,如果在同一位置找到两个或更多,我想检查这些配置文件是否相同。问题出现在某些年份,在同一位置没有任何配置文件,有些年份可能会有2,3或更多。我不知道如何使用" isequal"在一个循环内,并改变要比较的数组的数量。这是代码的改编:

% Data
>> profiles
    profiles = 

    1x3864 struct array with fields:
    position
    time
    temperature

>> size(years)    % Vector with each profile's time
    3864 1

>> size(position) % Vector with each profile's position
    3864 1

for ii=2000:2012   % Looping over years 2000 to 2012
    year_index=find(years==ii);               % Find profiles within each year
    [C,Ia,Ic]=unique(position(year_index));   % Find unique positions

    if length(Ia)~=length(Ic)                 % If there are repeated values

        for ij=1:length(Ia)                   % Loop over singlets
            repeated_index=year_index(Ic==ij) % Indexes of each position value

            if length(repeated_index)>1       % If it is a repeated value
            % Here is where I want to assess the equality

            if isequal(profiles(repeated_index).temperature)
            profiles(repeated_index(2:end))=NaN;
            end

            % However there aren't enough input arguments, sometimes it will 
            % be just a pair, and sometimes it will be up to 6 different 
            profiles to compare

            end
        end
    end
end

那么如何在循环中使用isequal,而不确认每次必须使用多少输入?作为提示,length(repeated_index)告诉我们每次有多少,但是如何构建动态isequal代码行?

我的目标是保持每个重复的集合,并保留所有不同的配置文件以进行更多检查。

感谢。随意询问更多信息或澄清。 (抱歉,对此不熟悉且不确定如何正确格式化代码段)

0 个答案:

没有答案